As the number of blockchain networks grows, the challenge of interoperability and cross-chain transactions becomes increasingly important. Blockchain bridging is emerging as a solution to this challenge, allowing different blockchain networks to communicate with each other and transfer assets seamlessly. In this blog post, we'll explore the concept of blockchain bridging and how to bridge fungible tokens from NEAR Testnet to Calimero and withdraw the tokens back to NEAR Testnet.
NEAR is a blockchain network that utilizes sharding scalability to increase its transaction processing capacity. Sharding involves dividing the network into smaller sub-networks or shards, each capable of processing transactions independently. Shard bridges are connections that allow communication between different shards within the NEAR network, enabling the transfer of assets between them. By bridging tokens from NEAR testnet to Calimero private shard, transactions become fast, free, and private, as nobody outside the Calimero private shard can see the transactions that are occurring within the shard.
To get started, ensure that you have the following:
Once you've signed into the Calimero console, you need to set up your FT Connector to be able to bridge tokens. FT Connector is a contract pair used to lock a fungible token on one chain and mint a wrapped fungible token on the other. It also burns the wrapped fungible token and unlocks it on the original chain.
Follow these steps to install the FT Connector:
After the installing, you'll need to provide access to all the accounts that want to bridge tokens. We'll do that by adding regex rules that'll allow bridging for all the accounts that match those rules. For the purpose of this tutorial, we will provide access to all the accounts using this regext (*) symbol.
The next step is to sync NEAR account with Calimero shard to be able to to call contract methods.
In the .env file update the following:
To call contract function from the CLI, we are going to first set up our public and private keys and then a create JSON files which will be used to call the function.
From the Explorer, select Transactions. From Transactions you can inspect activites such as: the account created, type of transaction carried out, the keys added to account etc.
To find our public key:
To get your private key follow these steps:
Note: Your account address is your NEAR account name
Now we have gotten the public and private keys, next is to create our JSON file which will be used for calling the contract function from the CLI
In the file copy paste the following (replace with your own details):
To interact with Calimero shard using near-cli, you need to set the token value using near set-api-key command.
Note: Replace AUTH_TOKEN with your token value
First, call wrap.test, which will call the fungible storage deposit for the accounts you'll be using. This will register the accounts in the fungible token. For this tutorial, we'll be using Wrap NEAR fungible tokens.
REGISTER_ACCOUNT_ID is the account name you get when you create your Near wallet account. You can also use it as a CALLER_ACCOUNT_ID. The CALLER_ACCOUNT_ID is the one that calls the function, while REGISTER_ACCOUNT_ID is the account that will be registered. CALLER_ACCOUNT_ID can be both the register and the caller
To register the account from your wallet, run the following code
FT Connector is used used as a locker. To find the locker account:
To register the FT Connector run the following:
Call near_deposit and deposit the amount of NEAR you want. This will swap your NEAR for Wrapped NEAR
After you have swaped your token, you can check your balance in the NEAR testnet using the following method:
You can also check the balance on the FT Connector by calling:
Note: Replace Shard_ID with the Shard name
When sending Wrapped NEAR to the FT connector, the account on the NEAR side has a locker functionality, while on the Calimero side there is an account called deployer (with an account ID ft_deployer.). Deployer will mint and distribute tokens to accounts in the shard.
You can check the list of all transactions in the console explorer.
You can check the balance of your account on the Calimero Side using wrap.ft_deployer, a representation of wrap.testnet fungible token on the Calimero side.
To bridge the token back to NEAR testnet, run the following:
You can check the withdrawn token status:
Bridging between NEAR and Calimero networks allows for seamless interoperability and transfering of tokens. In this tutorial, we have bridged fungible tokens from NEAR testnet to Calimero Shard and back. If you want to learn more about bridging, check out our Docs.