Build
Frontend Tutorials
toolkit
Class.zetachainclient

@zetachain/toolkit / ZetaChainClient

new ZetaChainClient()

new ZetaChainClient(params): ZetaChainClient

Initializes ZetaChainClient instance.

new ZetaChainClient({
  network: "testnet"
})

With an Ethers.js wallet:

const client = new ZetaChainClient({
  network: "testnet",
  wallet: ethers.Wallet.fromMnemonic(process.env.MNEMONIC as string),
});

With a signer:

const client = new ZetaChainClient({
  network: "testnet",
  signer: await ethers.getSigners(),
});

Use a custom RPC endpoint for ZetaChain or any connected chain:

const client = new ZetaChainClient({
  network: "testnet",
  chains: {
    zeta_testnet: {
      api: {
        url: "https://zetachain-testnet-archive.allthatnode.com:8545/${process.env.KEY}",
        type: "evm",
      },
    },
  },
});

Parameters

params: ZetaChainClientParams

Returns

ZetaChainClient

Defined in

client.ts:87 (opens in a new tab)

chains

chains: object

Index Signature

[key: string]: any

Defined in

client.ts:37 (opens in a new tab)


deposit()

deposit: (this, options) => Promise<any>

Initiates a deposit transaction of native gas or ERC-20 assets as ZRC-20 from a connected chain to ZetaChain.

Parameters

this: ZetaChainClient

ZetaChainClient instance.

options

Deposit options.

options.amount: string

Amount to be deposited in human readable form. For example, 1.5 ETH is "1.5".

options.chain: string

Label of the connected chain from which the deposit is made.

options.erc20?: string

If an ERC-20 token is being deposited, the address of the ERC-20 token contract. If not provided, the deposit is assumed to be in native gas token.

options.message?: [string[], string[]]

If a message is specified, ZetaChain will deposit tokens into the recipient contract and call with with the message as an argument.

options.recipient: string

Recipient address for the deposit. If not provided, the deposit is made to the signer's address.

Returns

Promise<any>

A promise that resolves with the transaction details upon success.

Defined in

client.ts:120 (opens in a new tab)


getBalances()

getBalances: (this, __namedParameters) => Promise<TokenBalance[]>

Get token balances of all tokens on all chains connected to ZetaChain.

Parameters

this: ZetaChainClient

ZetaChainClient instance.

__namedParameters

__namedParameters.btcAddress?: string

__namedParameters.evmAddress: string

Returns

Promise<TokenBalance[]>

Defined in

client.ts:114 (opens in a new tab)


getChainId()

getChainId: (this, chainNameOrAlias) => null | number

Get chain ID from a chain label.

Parameters

this: ZetaChainClient

ZetaChainClient instance.

chainNameOrAlias: string

Chain label like goerli_testnet

Returns

null | number

Defined in

client.ts:123 (opens in a new tab)


getEndpoint()

getEndpoint: (this, type, network) => any

Parameters

this: ZetaChainClient

type: any

network: any

Returns

any

Defined in

client.ts:113 (opens in a new tab)


getFees()

getFees: (this, gas) => Promise<Fees>

Parameters

this: ZetaChainClient

gas: Number

Returns

Promise<Fees>

Defined in

client.ts:117 (opens in a new tab)


getForeignCoins()

getForeignCoins: (this) => Promise<any>

Parameters

this: ZetaChainClient

Returns

Promise<any>

Defined in

client.ts:115 (opens in a new tab)


getPools()

getPools: (this) => Promise<any[]>

Parameters

this: ZetaChainClient

Returns

Promise<any[]>

Defined in

client.ts:118 (opens in a new tab)


getQuote()

getQuote: (this, inputAmount, inputToken, outputToken) => Promise<object>

Retrieves a quote for swapping input ZRC20 token to output ZRC20 token.

Parameters

this: ZetaChainClient

inputAmount: string

The amount of input ZRC20 token.

inputToken: string

outputToken: string

Returns

Promise<object>

  • An object containing the output amount and its decimals.
amount

amount: any

decimals

decimals: any = outputDecimals

Defined in

client.ts:124 (opens in a new tab)


getRefundFee()

getRefundFee: (this, inputZRC20) => Promise<object>

Calculates the refund fee in the input ZRC20 token.

Parameters

this: ZetaChainClient

inputZRC20: string

The input ZRC20 token address.

Returns

Promise<object>

  • An object containing the refund fee amount and its decimals.
amount

amount: any = withdrawFee

decimals

decimals: any = inputDecimals

Defined in

client.ts:126 (opens in a new tab)


getSupportedChains()

getSupportedChains: (this) => Promise<any>

Parameters

this: ZetaChainClient

Returns

Promise<any>

Defined in

client.ts:116 (opens in a new tab)


getWithdrawFeeInInputToken()

getWithdrawFeeInInputToken: (this, inputZRC20, outputZRC20) => Promise<object>

Calculates the withdraw fee in the input ZRC20 token for a given output ZRC20 token.

Parameters

this: ZetaChainClient

inputZRC20: string

The input ZRC20 token address.

outputZRC20: string

The output ZRC20 token address.

Returns

Promise<object>

  • An object containing the withdraw fee amount and its decimals.
amount

amount: any

decimals

decimals: any = inputDecimals

Defined in

client.ts:125 (opens in a new tab)


getZRC20FromERC20()

getZRC20FromERC20: (this, erc20) => Promise<any>

Retrieves the ZRC20 contract address for a given ERC20 token.

Parameters

this: ZetaChainClient

erc20: string

The ERC20 token address.

Returns

Promise<any>

  • The ZRC20 contract address.

Throws

Will throw an error if the ERC-20 token is not supported.

Defined in

client.ts:127 (opens in a new tab)


getZRC20GasToken()

getZRC20GasToken: (this, network) => Promise<any>

Retrieves the ZRC20 contract address for the gas token of a given network.

Parameters

this: ZetaChainClient

network: string

The network name.

Returns

Promise<any>

  • The ZRC20 contract address for the gas token.

Defined in

client.ts:128 (opens in a new tab)


network

network: string

Defined in

client.ts:38 (opens in a new tab)


sendZeta()

sendZeta: (this, options) => Promise<any>

Initiates a cross-chain transfer of ZETA tokens from the source chain to the destination chain.

Parameters

this: ZetaChainClient

ZetaChainClient instance.

options

Send ZETA options.

options.amount: string

Amount of ZETA tokens to be sent in human readable form.

options.chain: string

Source chain label.

options.destination: string

Destination chain label.

options.gasLimit?: Number = 500000

Optional gas limit on the destination chain.

options.recipient: string

Optional recipient address for the token transfer. If not provided, the token transfer is made to the signer's address.

Returns

Promise<any>

A promise that resolves with the transaction details upon success.

Defined in

client.ts:122 (opens in a new tab)


signer

signer: any

Defined in

client.ts:40 (opens in a new tab)


trackCCTX()

trackCCTX: (this, __namedParameters) => Promise<void>

Parameters

this: ZetaChainClient

__namedParameters

__namedParameters.emitter: any = null

__namedParameters.hash: string

__namedParameters.json: Boolean = false

Returns

Promise<void>

Defined in

client.ts:119 (opens in a new tab)


wallet

wallet: undefined | Wallet

Defined in

client.ts:39 (opens in a new tab)


withdraw()

withdraw: (this, options) => Promise<any>

Initiates a withdraw transaction of a ZRC-20 token from ZetaChain to a connected chain as a native gas or ERC-20 token.

Parameters

this: ZetaChainClient

ZetaChainClient instance.

options

Withdrawal options.

options.amount: string

Amount to be withdrawn in human readable form.

options.recipient: string

Recipient address for the withdrawal. If not provided, the withdrawal is made to the signer's address.

options.zrc20: string

ZRC-20 token contract address.

Returns

Promise<any>

A promise that resolves with the transaction details upon success.

Defined in

client.ts:121 (opens in a new tab)

getChains()

getChains(): object

Returns

object

Defined in

client.ts:109 (opens in a new tab)