ar.io Logoar.io Documentation
ar.io SDKARIO Contract

General

init()

Factory function that creates a read-only or writeable ARIO client. Providing signer plus rpcSubscriptions enables write methods (joinNetwork, delegateStake, buyRecord, etc.). Without a signer, the client is read-only.

import { ARIO } from "@ar.io/sdk";
import {
    createSolanaRpc,
    createSolanaRpcSubscriptions,
    createKeyPairSignerFromBytes,
} from "@solana/kit";

const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");

// read-only client
const ario = ARIO.init({ rpc });

// read-write client (needs rpcSubscriptions for sendAndConfirm)
const rpcSubscriptions = createSolanaRpcSubscriptions(
    "wss://api.mainnet-beta.solana.com",
);
const signer = await createKeyPairSignerFromBytes(/* 64-byte secret key */);
const arioWrite = ARIO.init({ rpc, rpcSubscriptions, signer });

getInfo()

Retrieves the information of the ARIO process.

const ario = ARIO.init({ rpc });
const info = await ario.getInfo();

Output:

{
    "Name": "AR.IO",
    "Ticker": "ARIO",
    "Logo": "",
    "Denomination": 6,
    "Handlers": [],
    "LastCreatedEpochIndex": 0,
    "LastDistributedEpochIndex": 0,
    "totalSupply": 1000000000000000,
    "protocolBalance": 0,
    "epochSettings": {
        "durationMs": 86400000,
        "prescribedNameCount": 25,
        "maxObservers": 50
    }
}

Note: Handlers, LastCreatedEpochIndex, and LastDistributedEpochIndex are placeholders on Solana (returned for backwards-compatible field shape with consumer code). totalSupply / protocolBalance are live reads from the ArioConfig PDA; epochSettings is live from the EpochSettings PDA. See src/solana/io-readable.ts for the exact projection.

getTokenSupply()

Retrieves the total supply of tokens, returned in mARIO. The total supply includes the following:

  • total - the total supply of all tokens
  • circulating - the total supply minus locked, withdrawn, delegated, and staked
  • locked - tokens that are locked in the protocol (a.k.a. vaulted)
  • withdrawn - tokens that have been withdrawn from the protocol by operators and delegators
  • delegated - tokens that have been delegated to gateways
  • staked - tokens that are staked in the protocol by gateway operators
  • protocolBalance - tokens that are held in the protocol's treasury. This is included in the circulating supply.
const ario = ARIO.init({ rpc });
const supply = await ario.getTokenSupply();
Output
{
    "total": 1000000000000000000,
    "circulating": 998094653842520,
    "locked": 0,
    "withdrawn": 560563387278,
    "delegated": 1750000000,
    "staked": 1343032770199,
    "protocolBalance": 46317263683761
}

getBalance()

Retrieves the balance of the specified wallet address.

const ario = ARIO.init({ rpc });
// the balance will be returned in mARIO as a value
const balance = await ario
    .getBalance({
        address: "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
    })
    .then((balance: number) => new mARIOToken(balance).toARIO()); // convert it to ARIO for readability

Output:

100000

getBalances()

Retrieves the balances of the ARIO process in mARIO, paginated and sorted by the specified criteria. The cursor used for pagination is the last wallet address from the previous request.

const ario = ARIO.init({ rpc });
const balances = await ario.getBalances({
    cursor: "-4xgjroXENKYhTWqrBo57HQwvDL51mMdfsdsxJy6Y2Z_sA",
    limit: 100,
    sortBy: "balance",
    sortOrder: "desc",
});

Output:

{
    "items": [
        {
            "address": "-4xgjroXENKYhTWqrBo57HQwvDL51mMvSxJy6Y2Z_sA",
            "balance": 1000000
        },
        {
            "address": "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck",
            "balance": 1000000
        }
        // ...98 other balances
    ],
    "hasMore": true,
    "nextCursor": "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck",
    "totalItems": 1789,
    "sortBy": "balance",
    "sortOrder": "desc"
}

transfer()

Transfers mARIO to the designated target recipient address. Requires signer to be provided on ARIO.init to sign the transaction.

Note: Requires signer to be provided on ARIO.init to sign the transaction.

const ario = ARIO.init({ rpc, rpcSubscriptions, signer });
const { id: txId } = await ario.transfer({
    target: "RecipientSolanaPubkeyBase58",
    qty: new ARIOToken(1000).toMARIO(),
});

How is this guide?