Establish a Client Connection

Establish a Connection and a Client Object

You will need to initialize a client to enable sending and receiving of information:

  • From the Aver (read-only) API

  • To-and-from the Solana blockchain / Aver on-chain program

Solana has multiple 'networks'.

mainnet-beta is the 'production' network, where real value is transacted and real costs (in SOL, or other tokens) are incurred with every action.

devnet is a development network, where transactions use 'test' SOL and tokens to experiment with protocols and new technologies.

Within the SDKs, there is a class called an 'AverClient' object. This has been designed to keep consistency between the point of interaction with the Aver API and the Solana blockchain consistent by network. If you are building your own integrations you will need to have tooling to interact with both and ensure they refer to the same network.

Below an AverClient object is initialized to interact with Solana devnet (and the corresponding devnet Aver API).

import asyncio
from solana.rpc.async_api import AsyncClient
from solana.rpc.types import TxOpts
from pyaver.enums import SolanaNetwork
from pyaver.aver_client import AverClient
from pyaver.constants import get_solana_endpoint, AVER_PROGRAM_IDS, get_aver_api_endpoint
from solana.rpc.commitment import Confirmed

opts = TxOpts(
    preflight_commitment=Confirmed
)

connection = AsyncClient(
    endpoint = get_solana_endpoint(SolanaNetwork.DEVNET),
    commitment = Confirmed,
    timeout = 30
)

client: AverClient = await AverClient.load(
    connection=connection, 
    owner=owner_keypair, 
    opts=opts, 
    network=SolanaNetwork.DEVNET, 
    program_ids=AVER_PROGRAM_IDS
)

If you're following along or experimenting with Solana for the first time it is strongly recommend that you interact via devnet first.

This is because a number of the steps following this one are significantly faster if you do not have to source external funding (for example, buying SOL and USDC from an exchange).

Program IDs are the public keys of the Aver Program (or 'smart contract').

Currently, there is only 1 program. However, the SDK allows for the possibility of loading multiple markets which are on different programs. This is to future-proof any integrations as much as possible in the event of a large overhaul.

RPC Nodes

When using the SDKs out of the box, the endpoints used are the default Solana RPC nodes. These nodes are fine for reasonable levels of use, but are subject to rate limiting and are not intended for heavy utilization.

You can read more about RPC Node considerations in the RPC Clients section.

Last updated