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

    Class Coin

    The Coin class provides methods for interacting with the legacy coins 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 Coin

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

      const supra = new SupraClient({ network: Network.TESTNET });
    • Reads the name, symbol and decimals of a coin type from the 0x1::coin::CoinInfo resource that the account defining the coin holds.

      Parameters

      • args: { coinType: `${string}::${string}::${string}` }
        • coinType: `${string}::${string}::${string}`

          Type of the coin, for example 0x1::supra_coin::SupraCoin

      Returns Promise<CoinInfo>

      CoinInfo

      When the coin type has no CoinInfo resource.

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

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

      async function runExample() {
      const coinType = "0x1::supra_coin::SupraCoin";
      const coinInfo = await supra.coin.getCoinInfo({ coinType: coinType });
      console.log(coinInfo);
      }

      runExample().catch(console.error);
    • Transfer SUPRA from one account to another with 0x1::supra_account::transfer_coins. The transfer moves SUPRA held in the sender's CoinStore or in its fungible asset store.

      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;
            receiverAccountAddress: AccountAddressInput;
            amount: number | bigint;
            optionalTransactionArgs?: OptionalTransactionArgs;
        }
        • senderAccount: SupraAccount

          The account sending the SUPRA.

        • receiverAccountAddress: AccountAddressInput

          The address of the account receiving the SUPRA. The account is created when it does not exist.

        • amount: number | bigint

          The amount of SUPRA to transfer, in quants.

        • 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.

      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

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

      runExample().catch(console.error);
    • Transfer a coin from one account to another with 0x1::supra_account::transfer_coins.

      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;
            receiverAccountAddress: AccountAddressInput;
            amount: number | bigint;
            coinType: `${string}::${string}::${string}`;
            optionalTransactionArgs?: OptionalTransactionArgs;
        }
        • senderAccount: SupraAccount

          The account sending the coin.

        • receiverAccountAddress: AccountAddressInput

          The address of the account receiving the coin.

        • amount: number | bigint

          The amount of the coin to transfer, in the smallest unit of the coin (quants for SUPRA).

        • coinType: `${string}::${string}::${string}`

          The type of the coin to transfer.

        • 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.

      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

      async function runExample() {
      const receiverAccountAddress = "0x2";
      const amount = 100n;
      const coinType = "0x1::supra_coin::SupraCoin";
      const transactionResponse = await supra.coin.transferCoin({ senderAccount: senderAccount, receiverAccountAddress: receiverAccountAddress, amount: amount, coinType: coinType });
      console.log(transactionResponse);
      }

      runExample().catch(console.error);