Burn & Mint tokens SDK Methods
In this section, we will learn about all the available Burn & Mint tokens methods provided by the SDK.
Prerequisites
- Initialize the SDK before using wallet methods. See the Quick Start Guide for details.
- All methods require a
wallet
. Refer tocreateWallet
for more information. - All methods require a
domain
parameter, which is the network domain where your wallet and providers such as blobbers, sharders, miners, and validators are deployed. GoSDK will send requests to this domain.
Burn & Mint tokens Methods
The initBridge
method must be called to initialize the bridge client before using the any of the burn and mint methods.
initBridge
Initializes the bridge client.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the bridge | |
wallet | ActiveWallet | Active wallet details | |
ethereumAddress | string | Ethereum address of the wallet owner | |
bridgeAddress | string | Address of the bridge contract on the Ethereum network | |
authorizersAddress | string | Address of the authorizers contract on the Ethereum network | |
tokenAddress | string | Address of the token contract on the Ethereum network | |
ethereumNodeURL | string | URL of the Ethereum node | |
gasLimit | number | Gas limit for the transactions | |
consensusThreshold | number | Consensus threshold for the transactions |
Example
import { initBridge } from '@zerochain/sdk'
await initBridge({
domain: 'mainnet.zus.network',
wallet: activeWallet,
ethereumAddress: '0x1234567890123456789012345678901234567890',
bridgeAddress: '0x7700D773022b19622095118Fadf46f7B9448Be9b',
authorizersAddress: '0x481daB4407b9880DE0A68dc62E6aF611c4949E42',
tokenAddress: '0xb9EF770B6A5e12E45983C5D80545258aA38F3B78',
ethereumNodeURL: 'https://virtual.mainnet.rpc.tenderly.co/039fdd4f-053c-4a81-9c76-db6b944c7414',
gasLimit: 3000000,
consensusThreshold: 75.0
})
burnZCN
Burns ZCN tokens.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details | |
amount | number | Amount of ZCN tokens to burn |
Return Type
Promise<string>
Example
import { burnZCN } from '@zerochain/sdk'
const transactionHash = await burnZCN({
domain: 'mainnet.zus.network',
wallet: activeWallet,
amount: 100
})
mintZCN
Mints ZCN tokens.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details | |
burnTxnHash | string | Hash of the burn transaction | |
timeout | number | Timeout in seconds (deprecated) |
The timeout
parameter is deprecated and may be removed in future versions.
Return Type
Promise<string>
Example
import { mintZCN } from '@zerochain/sdk'
const transactionHash = await mintZCN({
domain: 'mainnet.zus.network',
wallet: activeWallet,
burnTxnHash: '0x1234567890123456789012345678901234567890123456789012345678901234',
})
getMintWZCNPayload
Returns the Mint WZCN Payload for the given burn transaction hash.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details | |
burnTxnHash | string | Hash of the burn transaction |
Return Type
Promise<MintPayload>
MintPayload Type
type MintPayload = {
zcn_txn_id: string
amount: number
to: string
nonce: number
signatures: {
authorizer_id: string
signature: Uint8Array
}[]
}
Example
import { getMintWZCNPayload } from '@zerochain/sdk'
const mintPayload = await getMintWZCNPayload({
domain: 'mainnet.zus.network',
wallet: activeWallet,
burnTxnHash: '0x1234567890123456789012345678901234567890123456789012345678901234'
})
getUnprocessedWZCNBurnEvents
Returns all unprocessed WZCN burn events from the Ethereum network.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the request | |
wallet | ActiveWallet | Active Wallet details |
Return Type
Promise<BurnEvent[]>
BurnEvent Type
type BurnEvent = {
nonce: number
amount: number
hash: string
}
Example
import { getUnprocessedWZCNBurnEvents } from '@zerochain/sdk'
const burnEvents = await getUnprocessedWZCNBurnEvents({
domain: 'mainnet.zus.network',
wallet: activeWallet
})
getProcessedZCNBurnTickets
Returns all processed ZCN burn tickets burned for a certain Ethereum address.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details |
Return Type
Promise<BurnTicket[]>
BurnTicket Type
type BurnTicket = {
hash: string
amount: number
nonce: number
}
Example
import { getProcessedZCNBurnTickets } from '@zerochain/sdk'
const burnTickets = await getProcessedZCNBurnTickets({
domain: 'mainnet.zus.network',
wallet: activeWallet
})
estimateMintWZCNGasAmount
Performs gas amount estimation for the given Mint WZCN transaction.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details | |
from | string | Address of the sender | |
to | string | Address of the receiver | |
zcnTransaction | string | Hash of the ZCN transaction | |
amountToken | number | Amount of tokens to mint (as a string) | |
nonce | number | Nonce of the transaction | |
signaturesRaw | string[] | Encoded format (base-64) of the burn signatures received from the authorizers |
Return Type
Promise<string>
Example
import { estimateMintWZCNGasAmount } from '@zerochain/sdk'
const gasAmount = await estimateMintWZCNGasAmount({
domain: 'mainnet.zus.network',
wallet: activeWallet,
from: '0x1234567890123456789012345678901234567890',
to: '0x0987654321098765432109876543210987654321',
zcnTransaction: '0x1234567890123456789012345678901234567890123456789012345678901234',
amountToken: 10000000000,
nonce: 1,
signaturesRaw: ['signature1', 'signature2', 'signature3']
})
estimateBurnWZCNGasAmount
Performs gas amount estimation for the given burn WZCN transaction.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details | |
from | string | Address of the sender | |
to | string | Address of the receiver | |
amountTokens | number | Amount of tokens to burn |
Return Type
Promise<string>
Example
import { estimateBurnWZCNGasAmount } from '@zerochain/sdk'
const gasAmount = await estimateBurnWZCNGasAmount({
domain: 'mainnet.zus.network',
wallet: activeWallet,
from: '0x1234567890123456789012345678901234567890',
to: '0x0987654321098765432109876543210987654321',
amountTokens: 10000000000
})
estimateGasPrice
Performs gas estimation for the given transaction using Alchemy enhanced API, returning the approximate final gas fee.
Parameters
Name | Type | Description | Default value |
---|---|---|---|
domain | NetworkDomain | Network domain for the transaction | |
wallet | ActiveWallet | Active wallet details |
Return Type
Promise<string>
Example
import { estimateGasPrice } from '@zerochain/sdk'
const gasPrice = await estimateGasPrice({
domain: 'mainnet.zus.network',
wallet: activeWallet
})