Bitfinity Evm-client
Introduction
This plugin demonstrates the process of bridging tokens between an ICRC chain and an EVM chain. The bridge allows tokens to be transferred between these two blockchain environments. The provided test files utilize the Chain class to perform various actions related to token bridging.
Installation
Using NPM
npm install @infinityswapofficial/evm-client
Using Yarn
yarn add @infinityswapofficial/evm-client
Usage
import { Chain } from "@infinityswapofficial/evm-client";
const bridge = new Chain({
minterCanister,
Ic,
signer,
provider,
rpcUrl, // eg https://testnet.bitfinity.network
icHost, // Your icHost url
});
Find test files at src/tests
Add Operation Points
const operationReceipt = await bridge.add_operation_points();
Get Bitfinity Bridge Contract Address
Call the get_bft_bridge_contract
on the Chain
class to get bft bridge contract address
const bftBridgeContractAddress = await bridge.get_bft_bridge_contract();
Deploy a BFT Wrapped Token
In other to bridge, you must have a wrapped version of your token on bft. If the wrapped token already exists, the function will return the wrapped token and not create another. The function takes 3
parameters. The first being the name
of the token, the second the symbol
of the token and the last is the token in Id256
. Example below.
import { Chain } from "@infinityswapofficial/evm-client";
const ercToken = await bridge.deploy_bft_wrapped_token(
"Token",
"TKN",
tokenInId256,
);
Get Id256 of Token
For ICRC
Token
example
import {Id256Factory} from "@infinityswapofficial/evm-client";
tokenInId256 = Id256Factory.fromPrincipal(Principal_of_token)
For EVM
Token
example
import {Id256Factory} from "@infinityswapofficial/evm-client";
const chain_id = 355113
tokenInId256 = Id256Factory.fromAddress(new AddressWithChainID(erc20TokenAddress, chain_id))
Burning icrc Tokens
Burns a specified amount of ICRC tokens to initiate the creation of an ERC20 mint order. Operation_id is a unique number to add to your burn. This can be used to retrieve a burn or initialize one in case something goes wrong. You can generate one using bridge.generateOperationId()
or use your own format.
const operation_id = bridge.generateOperationId();
const signedMintOrder = await bridge.burn_icrc2_tokens(TOKEN_PRINCIPAL,amount, operation_id);
Mint ERC20 Token
Mints ERC20 tokens on the EVM chain using a previously generated mint order.
const signedMintOrder = await bridge.mintOrder(signedMintOrder);
Get all cached Transations
Retrieves cached transactions, including mint transactions.
const cachedMintTx = await bridge.getCacheTx(); // get burnt transaction hash
const cachedMintTx = await bridge.getCacheTx("evm_client_mint"); // get mint results
const cachedMintTx = await bridge.getCacheTx("evm_client_mint_order"); // get mint order
Burn ERC20 Token
Burn erc20 tokens
const burnTxHash = await bridge.burn_erc_20_tokens(ercToken, 1000000, 0);
Get Operation id from burnt transaction hash
Burn erc20 tokens
const operation_id = await bridge.get_operation_id(Principal.fromText(canisterIds.evm.local),burnTxHash!);
Minting ICRC Tokens after burning erc20 tokens
const mintResult = await bridge.mint_icrc_tokens(operation_id,Principal.fromText(canisterIds.token.local));
Get base token principal from wrapped erc20 token address
const baseTokenPrincipal = await bridge.get_base_token(ercToken.getAddress());