Utils

isAssetCacao or isAssetMaya

Checks whether an asset is AssetCacao or AssetMaya

Parameters

  • asset Asset

Returns boolean true or false

getDenom

Get denomination from Asset

Parameters

  • asset Asset

Returns string The denomination of the given asset.

assetFromDenom

Get Asset from denomination

Parameters

Returns (Asset | null) The asset of the given denomination.

isBroadcastSuccess

Response guard for transaction broadcast

Parameters

  • response any The response from the node.

Returns boolean true or false.

getPrefix

Get address prefix based on the network.

Parameters

  • network Network

Returns string The address prefix based on the network.*

registerDepositCodecs

Register type for encoding MsgDeposit messages

registerSendCodecs

Register type for encoding MsgSend messages

getDepositTxDataFromLogs

Parse transaction data from event logs

Parameters

  • logs Array<TxLog> List of tx logs
  • address Address Address to get transaction data for
  • senderAsset
  • receiverAsset

Returns TxData Parsed transaction data

getDefaultFees

Get the default fee.

Returns Fees The default fee.

getTxType

Get transaction type.

Parameters

  • txData string the transaction input data
  • encoding string base64 or hex

Returns string the transaction type.

getChainId

Helper to get MAYAChain's chain id

Parameters

buildUnsignedTx

Builds final unsigned TX

Parameters

  • $0 Object
    • $0.cosmosSdk
    • $0.txBody
    • $0.signerPubkey
    • $0.sequence
    • $0.gasLimit
  • cosmosSdk CosmosSDK
  • txBody txBody with encoded Msgs
  • signerPubkey signerPubkey string
  • sequence account sequence
  • gasLimit transaction gas limit

getEstimatedGas

Estimates usage of gas

Note: Be careful by using this helper function, it's still experimental and result might be incorrect. Change multiplier to get a valid estimation of gas.

Parameters

  • $0 Object
    • $0.cosmosSDKClient
    • $0.txBody
    • $0.privKey
    • $0.accountNumber
    • $0.accountSequence
    • $0.multiplier

buildDepositTx

Structure a MsgDeposit

Parameters

  • $0 Object
    • $0.msgNativeTx
    • $0.nodeUrl
    • $0.chainId
  • msgNativeTx MsgNativeTx Msg of type MsgNativeTx.
  • nodeUrl string Node url
  • ChainId chainId Chain id of the network

  • Throws "Invalid client url" Thrown if the client url is an invalid one.

Returns Tx The transaction details of the given transaction id.

buildTransferTx

Structure a MsgSend

Parameters

  • $0 Object
    • $0.fromAddress
    • $0.toAddress
    • $0.assetAmount
    • $0.assetDenom
    • $0.memo (optional, default '')
    • $0.nodeUrl
    • $0.chainId
  • fromAddress required, from address string
  • toAddress required, to address string
  • assetAmount required, asset amount string (e.g. "10000")
  • assetDenom required, asset denom string (e.g. "cacao")
  • memo optional, memo string

getBalance

Get the balance of a given address.

Parameters

  • $0 Object
    • $0.address
    • $0.assets
    • $0.cosmosClient
  • address Address By default, it will return the balance of the current wallet. (optional)
  • asset Asset If not set, it will return all assets available. (optional)
  • CosmosSDKClient cosmosClient

Returns Array<Balance> The balance of the address.

getExplorerUrl

Get the explorer url.

Parameters

  • network Network
    • network.root
  • network Network
    • network.root
  • Explorer ExplorerUrls urls

Returns string The explorer url for mayachain based on the given network.

getExplorerAddressUrl

Get explorer address url.

Parameters

  • $0 Object
    • $0.urls
    • $0.network
    • $0.address
  • Explorer ExplorerUrls urls
  • network Network
  • address Address

Returns string The explorer url for the given address.

getExplorerTxUrl

Get transaction url.

Parameters

  • $0 Object
    • $0.urls
    • $0.network
    • $0.txID
  • Explorer ExplorerUrls urls
  • network Network
  • txID TxHash

Returns string The explorer url for the given transaction id.