Skip to main content

How to bridge fungible tokens

This guide provides step-by-step instructions on how to bridge fungible tokens (FTs) from the NEAR Testnet to Calimero and withdraw them back to the NEAR Testnet. Please ensure that you have met the prerequisites mentioned in the previous section before proceeding.

Bridging FTs from NEAR to Calimero

To bridge an FT from NEAR Testnet to Calimero, follow these steps:

  1. Lock the desired NFT by calling a single transaction to transfer it to the FT Connector contract on NEAR. Ensure that you use the ft_transfer_call function instead of ft_transfer to prevent token loss.

    Here's an example of locking a fungible token on NEAR Testnet:

    near call ft-test.igi.testnet ft_transfer_call --args '{"receiver_id":"ft_connector.cali99.dev.calimero.testnet", "token_id":"0", "msg":""}' --accountId igi.testnet --depositYocto 1 --gas 300000000000000
  2. Once the token is transferred, the bridge service will be notified and attempt to verify the locking of tokens on NEAR. If the verification is successful, a wrapped token representing the FT will be minted on the Calimero shard.

danger

When locking FTs on the source side NFT Connector, you MUST use the ft_transfer_call function. If you try to use ft_transfer, the tokens will be LOST.

Withdrawing NFTs back to NEAR

To withdraw a bridged NFT from Calimero back to NEAR, follow these steps:

  1. Call the withdraw function on the bridged token contract deployed on Calimero.

    • This action will effectively burn the token on Calimero.
    • The bridge service will be notified of the burn event and attempt to verify it on the NFT Connector contract on NEAR.
    • If the verification is successful, the tokens will be unlocked and made available on NEAR Testnet.

    Here's an example of withdrawing/burning the NFT token on Calimero:

    calimero cali99-calimero-testnet call nft-test_igi.nft_deployer.cali99.calimero.testnet withdraw --args '{"token_id":"0"}' --accountId igi.testnet --depositYocto 1 --gas 300000000000000

Important Considerations

When bridging FTs from NEAR to Calimero, keep the following considerations in mind:

  • Use the ft_transfer_call function instead of ft_transfer when locking FTs on the source side FT Connector. Using ft_transfer can result in the loss of tokens.

  • Before withdrawing FTs from the destination side, ensure that the account performing the transfer is registered (storage deposit paid) on the original FT contract on the source side. If withdrawal is attempted before registration, the funds will be lost (locked on the connector on the source side). Contact the shard admin for assistance in such cases.

info

For a detailed, step-by-step guide on bridging FT tokens, refer to the tutorial on how to bridge fungible tokens from NEAR to Calimero Shard. The tutorial provides comprehensive instructions and visual aids to help you successfully navigate the bridging process.

Helper CLI

To interact with the Calimero side, you can create a Calimero alias using the following command:

alias calimero='calimero_wrapper() {
local command="$2";
local max_gas="300000000000000";
local node_url="https://api.dev.calimero.network/api/v1/shards/$1/neard-rpc/";
local args=();
if [[ "$command" == "call" ]]; then
args=("${@:2}");
near "${args[@]}" --gas $max_gas --nodeUrl "$node_url" --networkId "$1";
else
args=("${@:2}");
near "${args[@]}" --nodeUrl "$node_url" --networkId "$1";
fi
}; calimero_wrapper'

This alias allows you to use the calimero command in the terminal for interacting with the Calimero network.

JavaScript Example

Here is a JavaScript snippet that demonstrates how to perform a token withdrawal on Calimero:

const callWithdrawOnCalimero = {
contractId: 'wrap.ft_deployer.cali99.calimero.testnet',
methodName: 'withdraw',
args: {
amount: amount,
},
attachedDeposit: new BN('1'),
gas: new BN(MAX_GAS_LIMIT),
};

const withdrawTokensTx = await senderAccount.functionCall(callWithdrawOnCalimero);

Feel free to customize the contractId, methodName, and args based on your specific requirements.