supra-ts-sdk - v2.0.0
    Preparing search index...

    Class FungibleAsset

    The FungibleAsset class provides methods for interacting with the FungibleAsset on the Supra network.

    Hierarchy (View Summary)

    Index
    • The constructor function takes a NetworkConfig object as a parameter and assigns it to the networkInformation property.

      Parameters

      • networkInformation: NetworkConfig

        A NetworkConfig object that contains information about the network on which the Supra client is running.

      Returns FungibleAsset

      import { SupraClient,Network } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
    • Get the metadata of a fungible asset: the 0x1::fungible_asset::Metadata resource stored at the address of the asset.

      Parameters

      Returns Promise<FungibleAssetMetadata>

      A Promise that resolves to the metadata of the fungible asset.

      When the address holds no fungible asset metadata.

      import { SupraClient,Network } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });

      async function runExample() {
      const assetAddress = "0xa"; // the SUPRA fungible asset
      const fungibleAssetMetadata = await supra.fungibleAsset.getFungibleAssetMetadata({ assetAddress: assetAddress });
      console.log(fungibleAssetMetadata);
      }

      runExample().catch(console.error);
    • Beta

      Reads the accounting of native SUPRA across the chain's two VMs (GET /rpc/v4/supply/native): native SUPRA on SupraEVM, the value in flight between the two sides, the sub-quant remainder, the quants awaiting a burn, the total those claim against the SupraMVM escrow, and the escrow's own balance, all as of the height the node had executed to. Needs a node from supra_node_v12.0.0; Mainnet and Testnet nodes of supra_node_v11.7.x answer HTTP 404, which is thrown as SupraRouteUnsupportedError.

      Preview: wraps an API added in supra_node_v12.0.0, which may change until that release reaches Testnet.

      Returns Promise<NativeSupply>

      A Promise that resolves to the NativeSupply. escrow_shortfall_wei is the amount claimed beyond what the escrow holds and is "0" whenever the mirror is fully backed; escrow_balance_quants and escrow_shortfall_wei are null only when the node could not read the escrow. Wei figures are decimal strings. The *_quants figures are bigint and exact above Number.MAX_SAFE_INTEGER.

      When the node does not serve the route.

      import { Network, SupraClient } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.DEVNET });

      async function runExample() {
      const supply = await supra.fungibleAsset.getNativeSupply();
      console.log(supply.evm_supply_wei, supply.escrow_shortfall_wei, supply.in_flight.count);
      }

      runExample().catch(console.error);
    • Transfer the SUPRA fungible asset from one account to another (0x1::primary_fungible_store::transfer).

      The transfer moves SUPRA held in the sender's primary fungible store only; SUPRA held in a CoinStore is not part of it. The sender's fungible asset balance is read first, and when it is below amount the method throws SupraInsufficientFungibleAssetBalanceError, naming the fungible asset balance and the coin balance, without submitting a transaction. migrateCoinToFungibleStore moves the coin balance into the fungible store; supra.coin.transferSupraCoin transfers SUPRA held in either form.

      The sequence number comes from the client's counter unless optionalTransactionPayloadArgs.sequenceNumber is set, and the client submits its calls from one account one after another. The client checks the chain ID of its node before it signs; see SupraConfig.

      Parameters

      Returns Promise<SubmitTransactionResponse>

      A Promise that resolves to a SubmitTransactionResponse. Submit describes the statuses and errors of a submission.

      When the sender's fungible asset balance is below amount.

      When the estimating simulation or an enabled simulation does not succeed.

      When the node refuses the submission or a simulation because the gas unit price is below its minimum (this replaces SupraSimulationFailedError and SupraAPIError for that refusal).

      When enableWaitForTransaction is set and the transaction fails.

      When the submission request times out, fails before the node answers or is answered with a 5xx status other than 503 (after the wait, with enableWaitForTransaction).

      Before signing, when the chain ID is not the node's.

      import { Network, SupraAccount, SupraClient } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
      const senderAccount = new SupraAccount(); // an account that holds SUPRA in its fungible asset store

      async function runExample() {
      const receiverAccountAddress = "0x2";
      const amount = 100n;
      const transactionResponse = await supra.fungibleAsset.transferSupraFungibleAsset({ senderAccount: senderAccount, receiverAccountAddress: receiverAccountAddress, amount: amount });
      console.log(transactionResponse);
      }

      runExample().catch(console.error);
    • Migrates the sender's balance of a coin type from its CoinStore resource to the primary fungible store of the paired fungible asset (0x1::coin::migrate_to_fungible_store). The coin store is removed; the balance is unchanged as reported by 0x1::coin::balance and is available to fungible asset transfers afterwards. The transaction aborts when the chain has the migration disabled or the coin type has no coin info.

      The sequence number comes from the client's counter unless optionalTransactionPayloadArgs.sequenceNumber is set, and the client submits its calls from one account one after another. The client checks the chain ID of its node before it signs; see SupraConfig.

      Parameters

      • args: {
            senderAccount: SupraAccount;
            coinType?: `${string}::${string}::${string}`;
            optionalTransactionArgs?: OptionalTransactionArgs;
        }
        • senderAccount: SupraAccount

          The account whose balance is migrated.

        • OptionalcoinType?: `${string}::${string}::${string}`

          The coin type to migrate. Defaults to SUPRA, 0x1::supra_coin::SupraCoin.

        • OptionaloptionalTransactionArgs?: OptionalTransactionArgs

          Optional transaction arguments. The gas settings in optionalTransactionPayloadArgs apply to the transaction; without maxGas it is estimated (see OptionalTransactionPayloadArgs). The object is not modified.

      Returns Promise<SubmitTransactionResponse>

      A Promise that resolves to a SubmitTransactionResponse. Submit describes the statuses and errors of a submission.

      import { Network, SupraAccount, SupraClient } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
      const senderAccount = new SupraAccount(); // an account that holds SUPRA in its CoinStore

      async function runExample() {
      const transactionResponse = await supra.fungibleAsset.migrateCoinToFungibleStore({
      senderAccount: senderAccount,
      optionalTransactionArgs: { enableTransactionWaitAndSimulationArgs: { enableWaitForTransaction: true } },
      });
      console.log(transactionResponse);
      }

      runExample().catch(console.error);
    • Transfer a fungible asset from one account to another (0x1::primary_fungible_store::transfer). When assetAddress is the SUPRA fungible asset (0xa) the method behaves as transferSupraFungibleAsset: it throws SupraInsufficientFungibleAssetBalanceError without submitting when the sender's fungible asset balance is below amount. The sequence number comes from the client's counter unless optionalTransactionPayloadArgs.sequenceNumber is set, and the client submits its calls from one account one after another. The client checks the chain ID of its node before it signs; see SupraConfig.

      Parameters

      Returns Promise<SubmitTransactionResponse>

      A Promise that resolves to a SubmitTransactionResponse. Submit describes the statuses and errors of a submission.

      When the estimating simulation or an enabled simulation does not succeed.

      When the node refuses the submission or a simulation because the gas unit price is below its minimum (this replaces SupraSimulationFailedError and SupraAPIError for that refusal).

      When enableWaitForTransaction is set and the transaction fails.

      When the submission request times out, fails before the node answers or is answered with a 5xx status other than 503 (after the wait, with enableWaitForTransaction).

      Before signing, when the chain ID is not the node's.

      import { Network, SupraAccount, SupraClient } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
      const senderAccount = new SupraAccount(); // an account that holds the fungible asset

      async function runExample() {
      const receiverAccountAddress = "0x2";
      const amount = 100n;
      const assetAddress = "0x000000000000000000000000000000000000000000000000000000000000000a";
      const transactionResponse = await supra.fungibleAsset.transferFungibleAsset({ senderAccount: senderAccount, receiverAccountAddress: receiverAccountAddress, amount: amount, assetAddress: assetAddress });
      console.log(transactionResponse);
      }

      runExample().catch(console.error);