Class SupraClient

Provides methods for interacting with supra rpc node.

Constructors

Properties

chainId: ChainId
supraNodeURL: string

Methods

  • Create raw transaction object for entry_function_payload type tx

    Parameters

    • senderAddr: HexString

      Sender account address

    • senderSequenceNumber: bigint

      Sender account sequence number

    • moduleAddr: string

      Target module address

    • moduleName: string

      Target module name

    • functionName: string

      Target function name

    • functionTypeArgs: TypeTag[]

      Target function type args

    • functionArgs: Uint8Array[]

      Target function args

    • Optional optionalTransactionPayloadArgs: OptionalTransactionPayloadArgs

      Optional arguments for transaction payload

    Returns Promise<RawTransaction>

    Serialized raw transaction object

    Example

    let supraCoinTransferRawTransaction = await supraClient.createRawTxObject(
    senderAccount.address(),
    (
    await supraClient.getAccountInfo(senderAccount.address())
    ).sequence_number,
    "0000000000000000000000000000000000000000000000000000000000000001",
    "supra_account",
    "transfer",
    [],
    [receiverAddress.toUint8Array(), BCS.bcsSerializeUint64(10000)]
    );
  • Create serialized raw transaction for entry_function_payload type tx Under the hood the method utilizes createRawTxObject method to create a raw transaction and then it serializes using bcs serializer

    Parameters

    • senderAddr: HexString

      Sender account address

    • senderSequenceNumber: bigint

      Sender account sequence number

    • moduleAddr: string

      Target module address

    • moduleName: string

      Target module name

    • functionName: string

      Target function name

    • functionTypeArgs: TypeTag[]

      Target function type args

    • functionArgs: Uint8Array[]

      Target function args

    • Optional optionalTransactionPayloadArgs: OptionalTransactionPayloadArgs

      Optional arguments for transaction payload

    Returns Promise<Uint8Array>

    Serialized raw transaction object

  • Get Coin balance of given account

    Parameters

    • account: HexString

      Supra account address for getting balance

    • coinType: string

      Type of a coin resource

    Returns Promise<bigint>

    Supra Balance

  • Get transactions sent by the account and Coin transfer related transactions

    Parameters

    • account: HexString

      Supra account address

    • count: number = DEFAULT_RECORDS_ITEMS_COUNT

      Number of coin transfer transactions and account sent transaction to be considered, For instance if the value is N so total N*2 transactions will be returned.

    Returns Promise<TransactionDetail[]>

    List of TransactionDetail

  • Get Supra balance of given account

    Parameters

    • account: HexString

      Supra Account address for getting balance

    Returns Promise<bigint>

    Supra Balance

  • Get Chain Id Of Supra Network

    Returns Promise<ChainId>

    Chain Id of network

  • Get Supra balance of given account

    Parameters

    • coinType: string

      Type of a coin resource

    Returns Promise<CoinInfo>

    CoinInfo

  • Get current mean_gas_price

    Returns Promise<bigint>

    Current mean_gas_price

  • Get data of resource held by given supra account

    Parameters

    • account: HexString

      Hex-encoded 32 byte Supra account address

    • resourceType: string

      Type of a resource

    Returns Promise<any>

    Resource data

    Example

    let supraCoinInfo = await supraClient.getResourceData(
    new HexString("0x1"),
    "0x1::coin::CoinInfo<0x1::supra_coin::SupraCoin>"
    )
  • Generate SendTxPayload using RawTransaction to send transaction request Generated data can be used to send transaction directly using /rpc/v1/transactions/submit endpoint of rpc_node

    Parameters

    • senderAccount: SupraAccount

      Sender KeyPair

    • rawTxn: RawTransaction

      Raw transaction data

    Returns SendTxPayload

    SendTxPayload

  • Get transaction details of given transaction hash

    Parameters

    • account: HexString

      Hex-encoded 32 byte Supra account address

    • transactionHash: string

      Hex-encoded 32 byte transaction hash for getting transaction details

    Returns Promise<null | TransactionDetail>

    TransactionDetail

  • Get status of given supra transaction

    Parameters

    • transactionHash: string

      Hex-encoded 32 byte transaction hash for getting transaction status

    Returns Promise<null | TransactionStatus>

    TransactionStatus

  • Check whether given account exists onchain or not

    Parameters

    • account: HexString

      Hex-encoded 32 byte Supra account address

    Returns Promise<boolean>

    true if account exists otherwise false

  • Publish package or module on supra network

    Parameters

    • senderAccount: SupraAccount

      Module Publisher KeyPair

    • packageMetadata: Uint8Array

      Package Metadata

    • modulesCode: Uint8Array[]

      module code

    • Optional optionalTransactionArgs: OptionalTransactionArgs

      optional arguments for transaction

    Returns Promise<TransactionResponse>

    TransactionResponse

  • Sends multi-agent transaction

    Parameters

    • senderAccountAddress: string

      Account address of tx sender

    • secondarySignersAccountAddress: string[]

      List of account address of tx secondary signers

    • rawTxn: RawTransaction

      The raw transaction to be submitted

    • senderAuthenticator: AccountAuthenticatorEd25519

      The sender account authenticator

    • secondarySignersAuthenticator: AccountAuthenticatorEd25519[]

      List of the secondary signers account authenticator

    • Optional enableTransactionWaitAndSimulationArgs: EnableTransactionWaitAndSimulationArgs

      enable transaction wait and simulation arguments

    Returns Promise<TransactionResponse>

    TransactionResponse

  • Parameters

    • isGetMethod: boolean
    • subURL: string
    • Optional data: any

    Returns Promise<AxiosResponse<any, any>>

  • Sends sponsor transaction

    Parameters

    • senderAccountAddress: string

      Account address of tx sender

    • feePayerAddress: string

      Account address of tx fee payer

    • secondarySignersAccountAddress: string[]

      List of account address of tx secondary signers

    • rawTxn: RawTransaction

      The raw transaction to be submitted

    • senderAuthenticator: AccountAuthenticatorEd25519

      The sender account authenticator

    • feePayerAuthenticator: AccountAuthenticatorEd25519

      The feepayer account authenticator

    • secondarySignersAuthenticator: AccountAuthenticatorEd25519[] = []

      An optional array of the secondary signers account authenticator

    • Optional enableTransactionWaitAndSimulationArgs: EnableTransactionWaitAndSimulationArgs

      enable transaction wait and simulation arguments

    Returns Promise<TransactionResponse>

    TransactionResponse

  • Send entry_function_payload type tx using serialized raw transaction data

    Parameters

    Returns Promise<TransactionResponse>

    TransactionResponse

  • Simulate a transaction using the provided transaction payload

    Parameters

    Returns Promise<any>

    Transaction simulation result

  • Simulate a transaction using the provided Serialized raw transaction data

    Parameters

    • senderAccountAddress: HexString

      Tx sender account address

    • txAuthenticator: AnyAuthenticatorJSON

      Transaction authenticator

    • serializedRawTransaction: Uint8Array

      Serialized raw transaction data

    Returns Promise<any>

    Transaction simulation result

  • Transfer custom type of coin

    Parameters

    • senderAccount: SupraAccount

      Sender KeyPair

    • receiverAccountAddr: HexString

      Receiver Supra Account address

    • amount: bigint

      Amount to transfer

    • coinType: string

      Type of custom coin

    • Optional optionalTransactionArgs: OptionalTransactionArgs

      optional arguments for transaction

    Returns Promise<TransactionResponse>

    TransactionResponse

  • Create signed transaction payload

    Parameters

    • senderAccount: SupraAccount

      Sender KeyPair

    • rawTxn: RawTransaction

      Raw transaction payload

    Returns SignedTransaction

    SignedTransaction

  • Generate transaction hash locally

    Parameters

    • signedTransaction: SignedTransaction

      Signed transaction payload

    Returns string

    SignedTransaction

    Example

     let supraCoinTransferSignedTransaction = SupraClient.createSignedTransaction(
    senderAccount,
    supraCoinTransferRawTransaction
    );
    console.log(
    SupraClient.deriveTransactionHash(supraCoinTransferSignedTransaction)
    );
  • Creates and initializes SupraClient instance The chain id will be fetched from the provided url

    Parameters

    • url: string

      rpc url of supra rpc node

    Returns Promise<SupraClient>

    SupraClient initialized instance

    Example

    let supraClient = await SupraClient.init(
    "http://localhost:27001/"
    );
  • Signs a multi transaction type (multi agent / fee payer) and returns the signer authenticator to be used to submit the transaction.

    Parameters

    • signer: SupraAccount

      the account to sign on the transaction

    • rawTxn: MultiAgentRawTransaction | FeePayerRawTransaction

      a MultiAgentRawTransaction or FeePayerRawTransaction

    Returns AccountAuthenticatorEd25519

    signer authenticator

  • Generate ed25519_signature for supra transaction using RawTransaction

    Parameters

    • senderAccount: SupraAccount

      the account to sign on the transaction

    • rawTxn: AnyRawTransaction

      a RawTransaction, MultiAgentRawTransaction or FeePayerRawTransaction

    Returns HexString

    ed25519 signature in HexString