Class Arc59

Utilities for interacting with the ARC-59 Router smart contract on Algorand.

Remarks

ARC-59 defines an inbox-based routing scheme for ASAs. This class composes transactions to send assets to a router, and for receivers to claim or reject assets from their ARC-59 inbox. Read-only methods leverage simulation to query contract state without sending transactions.

Constructors

Methods

  • Claim a routed ASA from the receiver's ARC-59 inbox.

    If the receiver lacks the opt-in to the ASA, this method composes the opt-in transaction automatically. If the inbox holds excess ALGO above min-balance, a claim of ALGO is also composed so the fee covers the additional calls.

    Parameters

    • params: {
          assetId: number;
          network: Network;
          receiver: {
              address: string;
              signer: TransactionSigner;
          };
      }

      Claim parameters.

      • assetId: number

        ASA identifier to claim.

      • network: Network

        Target network.

      • receiver: {
            address: string;
            signer: TransactionSigner;
        }

        Receiver address and signer authorizing the claim.

        • address: string
        • signer: TransactionSigner

    Returns Promise<string>

    The transaction ID of the submitted claim group.

    Example

    const txId = await Arc59.claimAsset({
    network: 'testnet',
    receiver: { address: receiverAddr, signer },
    assetId: 12345,
    });
  • Resolve the ARC-59 router application ID and address for a given network.

    Parameters

    • network: Network

      Target network, e.g. 'mainnet' or 'testnet'.

    Returns {
        appAddress: Address;
        appId: number;
    }

    Object containing appId and appAddress.

    • appAddress: Address
    • appId: number

    Example

    const { appId, appAddress } = Arc59.getAppInfo('testnet');
    console.log(appId, appAddress);
  • Simulate the send flow and fetch information required to send an asset via ARC-59.

    Parameters

    • network: Network

      Target network.

    • assetId: number

      ASA identifier to send.

    • receiver: string

      Receiver's Algorand address.

    Returns Promise<{
        itxns: bigint;
        mbr: bigint;
        receiverAlgoNeededForClaim: bigint;
        receiverOptedIn: boolean;
        routerOptedIn: boolean;
    }>

    Simulation result including:

    • itxns: total inner transactions expected
    • mbr: minimum balance requirement to cover during the send
    • routerOptedIn: whether the router is opted into the asset
    • receiverOptedIn: whether the receiver is opted into the asset
    • receiverAlgoNeededForClaim: ALGO needed by receiver to claim (in microalgos)

    Throws

    Error if simulation fails or no return value is produced.

    Example

    const info = await Arc59.getAssetSendInfo('testnet', 12345, receiverAddr);
    if (!info.receiverOptedIn) {
    // compose routed send using Arc59.sendAsset
    }
  • List ASA holdings currently held in a receiver's ARC-59 inbox.

    Parameters

    • params: {
          network: Network;
          receiver: string;
      }

      Query parameters.

      • network: Network

        Target network.

      • receiver: string

        Receiver's Algorand address.

    Returns Promise<{
        amount: number;
        assetId: number;
        isFrozen: boolean;
    }[]>

    Array of assets in the inbox with assetId, amount, and isFrozen.

    Example

    const assets = await Arc59.getAssetsInInbox({ network: 'testnet', receiver: addr });
    
  • Get the ARC-59 inbox address for a receiver.

    Parameters

    • network: Network

      Target network.

    • receiver: string

      Receiver's Algorand address.

    Returns Promise<string>

    The inbox account address, or the zero address if not created.

    Throws

    Error if simulation does not return an inbox address.

    Example

    const inbox = await Arc59.getInboxAddress('testnet', receiverAddr);
    
  • Check if an address is opted-in to a given ASA.

    Parameters

    • network: Network

      Target network.

    • assetId: number

      ASA identifier.

    • address: string

      Account address to check.

    Returns Promise<boolean>

    true if the account is opted-in, otherwise false.

    Example

    const opted = await Arc59.isOptedIn('testnet', 12345, addr);
    
  • Reject a routed ASA from the receiver's ARC-59 inbox.

    Parameters

    • params: {
          assetId: number;
          network: Network;
          receiver: {
              address: string;
              signer: TransactionSigner;
          };
      }

      Reject parameters.

      • assetId: number

        ASA identifier to reject.

      • network: Network

        Target network.

      • receiver: {
            address: string;
            signer: TransactionSigner;
        }

        Receiver address and signer authorizing the rejection.

        • address: string
        • signer: TransactionSigner

    Returns Promise<string>

    The transaction ID of the submitted reject group.

    Example

    const txId = await Arc59.rejectAsset({
    network: 'testnet',
    receiver: { address: receiverAddr, signer },
    assetId: 12345,
    });
  • Send an ASA to a receiver using ARC-59.

    If the receiver is already opted-in, a direct transfer is submitted. Otherwise, a composed transaction group routes the asset through the ARC-59 router so the receiver can later claim it from their inbox.

    Parameters

    • params: {
          amount: number;
          assetId: number;
          network: Network;
          receiver: string;
          sender: {
              address: string;
              signer: TransactionSigner;
          };
      }

      Send parameters.

      • amount: number

        Amount to send (base units).

      • assetId: number

        ASA identifier to send.

      • network: Network

        Target network.

      • receiver: string

        Receiver account address.

      • sender: {
            address: string;
            signer: TransactionSigner;
        }

        Sender address and signer for authorizing transactions.

        • address: string
        • signer: TransactionSigner

    Returns Promise<string>

    The transaction ID of the submitted group (last tx for routed send, or lone transfer tx for direct send).

    Example

    const txId = await Arc59.sendAsset({
    network: 'testnet',
    assetId: 12345,
    amount: 10,
    receiver: receiverAddr,
    sender: { address: senderAddr, signer }
    });