Client
Extends xchain_client_1.BaseXChainClient
Custom EVM client
Parameters
paramsEVMClientParamsparams.chainparams.gasAssetparams.gasAssetDecimalsparams.defaultsparams.network(optional, defaultxchain_client_1.Network.Mainnet)params.feeBoundsparams.providersparams.phrase(optional, default'')params.rootDerivationPathsparams.explorerProvidersparams.dataProviders
purgeClient
Purge client.
Returns void
getAddress
Parameters
walletIndex(optional, default0)
Meta
- deprecated: this function eventually will be removed use getAddressAsync instead
getAddressAsync
Get the current address.
Parameters
-
walletIndexnumber (optional) HD wallet index (optional, default0) - Throws any Error Thrown if HDNode is not defined. Note: A phrase is needed to create a wallet and to derive an address from it.
- Throws any Error Thrown if wallet index < 0.
Returns Address The current address.
getWallet
Get etherjs wallet interface.
Parameters
-
walletIndexnumber (optional) HD wallet index (optional, default0) -
Throws any Error Thrown if HDNode is not defined. Note: A phrase is needed to create a wallet and to derive an address from it.
Returns Wallet The current etherjs wallet interface.
getProvider
Get etherjs Provider interface.
Returns Provider The current etherjs Provider interface.
getExplorerUrl
Get the explorer url.
Returns string The explorer url for ethereum based on the current network.
getAssetInfo
Returns any asset info
getExplorerAddressUrl
Get the explorer url for the given address.
Parameters
addressAddress
Returns string The explorer url for the given address.
getExplorerTxUrl
Get the explorer url for the given transaction id.
Parameters
txIDstring
Returns string The explorer url for the given transaction id.
setNetwork
Set/update the current network.
Parameters
-
networkNetwork -
Throws
"Network must be provided"Thrown if network has not been set before.
Returns void
setPhrase
Set/update a new phrase (Eg. If user wants to change wallet)
Parameters
phrasestring A new phrase.-
walletIndexnumber (optional) HD wallet index (optional, default0) - Throws
"Invalid phrase"Thrown if the given phase is invalid.
Returns Address The address from the given phrase
validateAddress
Validate the given address.
Parameters
addressAddress
Returns boolean true or false
getBalance
Get the balance of a given address.
Parameters
addressAddress By default, it will return the balance of the current wallet. (optional)-
assets - Throws
"Invalid asset"throws when the give asset is an invalid one
Returns Array<Balance> The all balance of the address.
getTransactions
Get transaction history of a given address with pagination options. By default it will return the transaction history of the current wallet.
Parameters
paramsTxHistoryParams The options to get transaction history. (optional)
Returns TxsPage The transaction history.
getTransactionData
Get the transaction details of a given transaction id.
Parameters
txIdstring The transaction id.-
assetAddressstring The asset address. (optional) - Throws
"Need to provide valid txId"Thrown if the given txId is invalid.
Returns Tx The transaction details of the given transaction id.
call
Call a contract function.
Parameters
$0Object$0.signer$0.contractAddress$0.walletIndex(optional, default0)$0.abi$0.funcName$0.funcParams(optional, default[])
Signersigner (optional) The address a transaction is send from. If not set, signer will be defined based onwalletIndexcontractAddressAddress The contract address.walletIndexnumber (optional) HD wallet indexabiContractInterface The contract ABI json.funcNamestring The function to be called.funcParamsArray<unknown> (optional) The parameters of the function.
Returns T The result of the contract function call.
estimateCall
Call a contract function.
Parameters
$0Object$0.contractAddress$0.abi$0.funcName$0.funcParams(optional, default[])
contractAddressAddress The contract address.abiContractInterface The contract ABI json.funcNamestring The function to be called.funcParamsArray<any> The parameters of the function.walletIndexnumber (optional) HD wallet index
Returns BigNumber The result of the contract function call.
isApproved
Check allowance.
Parameters
$0Object$0.contractAddress$0.spenderAddress$0.amount$0.walletIndex
contractAddressAddress The contract address.spenderAddressAddress The spender address.amountBaseAmount The amount to check if it's allowed to spend or not (optional).walletIndexnumber (optional) HD wallet index
Returns boolean true or false.
approve
Check allowance.
Parameters
$0Object$0.contractAddress$0.spenderAddress$0.feeOption(optional, defaultxchain_client_1.FeeOption.Fastest)$0.amount$0.walletIndex(optional, default0)$0.signer
contractAddressAddress The contract address.spenderAddressAddress The spender address.Signersigner (optional) The address a transaction is send from. If not set, signer will be defined based onwalletIndexFeeOptionfeeOption Fee option (optional)amountBaseAmount The amount of token. By default, it will be unlimited token allowance. (optional)-
walletIndexnumber (optional) HD wallet index - Throws any Error If gas could not been estimated
Returns TransactionResponse The transaction result.
estimateApprove
Estimate gas for calling approve.
Parameters
$0Object$0.fromAddress$0.contractAddress$0.spenderAddress$0.amount
contractAddressAddress The contract address.spenderAddressAddress The spender address.fromAddressAddress The address the approve transaction is sent from.amountBaseAmount The amount of token. By default, it will be unlimited token allowance. (optional)
Returns BigNumber Estimated gas
transfer
Transfers ETH or ERC20 token
Note: A given feeOption wins over gasPrice and gasLimit
Parameters
$0Object$0.walletIndex(optional, default0)$0.signer$0.asset(optional, defaultthis.gasAsset)$0.memo$0.amount$0.recipient$0.feeOption(optional, defaultxchain_client_1.FeeOption.Fast)$0.gasPrice$0.maxFeePerGas$0.maxPriorityFeePerGas$0.gasLimit
paramsTxParams The transfer options.Signersigner (optional) The address a transaction is send from. If not set, signer will be defined based onwalletIndexFeeOptionfeeOption Fee option (optional)BaseAmountgasPrice Gas price (optional)-
BigNumbergasLimit Gas limit (optional) - Throws any Error Thrown if address of given
Assetcould not be parsed
Returns TxHash The transaction hash.
estimateGasPrices
Estimate gas price.
Parameters
protocolProtocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
Returns GasPrices The gas prices (average, fast, fastest) in Wei (BaseAmount)
estimateGasLimit
Estimate gas.
Parameters
paramsTxParams The transaction and fees options.params.assetparams.recipientparams.amountparams.memoparams.from
- Throws any Error Thrown if address could not parsed from given ERC20 asset
Returns BaseAmount The estimated gas fee.
estimateFeesWithGasPricesAndLimits
Estimate gas prices/limits (average, fast fastest).
Parameters
paramsTxParams
Returns FeesWithGasPricesAndLimits The estimated gas prices/limits.
prepareTx
Prepare transfer.
Parameters
paramsTxParams&Address&FeeOption&BaseAmount&BigNumber The transfer options.params.senderparams.asset(optional, defaultthis.gasAsset)params.memoparams.amountparams.recipient
Returns PreparedTx The raw unsigned transaction.
prepareApprove
Prepare transfer.
Parameters
paramsApproveParams&Address&FeeOption&BaseAmount&BigNumber The transfer options.params.contractAddressparams.spenderAddressparams.amountparams.sender
Returns PreparedTx The raw unsigned transaction.