How to bridge ft tokens from NEAR to Calimero
Calimero blog back button
Back to all posts
May 4, 2023
-
Favour Kelvin
  • Engineering
  • Tutorials

Bridging Fungible Tokens from NEAR to Calimero Shard: A Step-by-Step Tutorial

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.

The concept of Bridging

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.

Prerequisites

To get started, ensure that you have the following:

Step 1: Install the Bridge (FT Connector)

FT Connector

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:

     
  1. Select the shard you want to use.
  2.  
  3. Select Bridge from the left side navigation bar
  4.  
  5. Select FT Connector.
  6.  
  7. Click on Install FT bridge.
  8.  

Step 2: FT Connector Regex

Permission mangement

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.

     
  1. Select Bridge from the left side navigation bar
  2.  
  3. Select Permissions Management
  4.  
  5. Add .* as the Regex to the FT Connector Regex Rules  
  6. Click on FT Connector
  7.  
FT regex

Step 3: Sync NEAR account in Calimero Shard

The next step is to sync NEAR account with Calimero shard to be able to to call contract methods.

Creating Auth token

         
  • Log into your Calimero Network account
  •      
  • Select Security from the left side navigation bar
  •      
  • Select Tokens
  •      
  • Click on Create new token
  •      
  • Choose a name for your auth token
  •      
  • Select a duration for the token
  •      
  • Configure the token's permissions by selecting the appropriate checkboxes
  •      
  • Click on Generate Token.
  •      
  • Once the token is issued, copy it to your clipboard or request it to be sent to you via email
  •      
  • Save the token
  •      
Create Calimero Console access token
     

Installing Calimero SDK and setting up Env Variables

           
  • Open up the codebase in your editor
  •        
  • Navigate to the examples folder
  •        
           
  • Navigate to simple-login/.env
  •        
calimero sdk example
           

In the .env file update the following:

           
  • VITE_CALIMERO_URL: This is the RPC endpoint which can found in the Calimero console
  •        
  • VITE_CALIMERO_TOKEN: This is the auth token created
  •        
  • Install and run using the following command
  •        
         

Connecting NEAR Wallet with Calimero Shard

           
  • Open http://localhost:5173/
  •        
  • Click Login with NEAR
  •        
  • Create your account or import an existing account.
  •        
  • Click on Next
  •        
  • Click on Connect
  •        
Connect NEAR to Calimero
         

Step 4: Call contract function from the CLI

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.

Finding the public key

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.

Calimero Explorer

To find our public key:

     
  • Click on the transaction ADD_KEY from our synced account
  •  
  • Click on Execution Plan
  •  
  • Copy your Public key from the JSON
public key

Finding the private key

To get your private key follow these steps:

     
  • Go to your NEAR wallet
  •  
  • Click on Accounts
  •  
  • Click on Export Local Private Key
  •  
  • Enter your address to view the private key
  •    

Note: Your account address is your NEAR account name

     
private key

Creating a JSON file

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

     
  • Create a ~/.near-credentials folder
  •  
  • Create a .json file
  •  

In the file copy paste the following (replace with your own details):

     

Step 5: Setting up an API key

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

Step 6: Registering Account in the FT

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.

Registering the account from the wallet

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

Registering FT Connector

FT Connector is used used as a locker. To find the locker account:

     
  1. Select Bridge from the left side navigation bar
  2.  
  3. Select FT Connector.
  4.  
  5. Click on Calimero Contracts

Connect NEAR to Calimero

To register the FT Connector run the following:

     
  • Replace SHARD_ID with your shard name. Alternatively, you can copy the FT Connector account id and replace the ft_connector.SHARD_ID.calimero.testnet with it
  •  
  • The CALLER_ACCOUNT_ID should be the account name you get when you create your NEAR wallet account.

Registering FT token

     
  • From the FT Connector, click on the Register FT button
  •  
       
  • Add your FT contract address (in our case it's wrap.testnet)
  •  
  • Click on the Register button
  •    
     

Step 7: Swapping NEAR for Wrapped NEAR

Call near_deposit and deposit the amount of NEAR you want. This will swap your NEAR for Wrapped NEAR

Viewing the balance on NEAR testnet

After you have swaped your token, you can check your balance in the NEAR testnet using the following method:

Viewing the balance in the FT Connector

You can also check the balance on the FT Connector by calling:

Note: Replace Shard_ID with the Shard name

Step 8: Sending Wrapped NEAR to the FT Connector

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.

Step 9: Viewing the FT balance in Calimero Shard

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.

     
  • Replace the SHARD_ID with your shard name.
  •  
  • Replace CALLER_ACCOUNT_ID with your NEAR wallet account name.

Step 10: Withdrawing FT from Calimero Shard to NEAR testnet

To bridge the token back to NEAR testnet, run the following:

You can check the withdrawn token status:

     
  1. Select Explorer from the left side navigation bar
  2.  
  3. Select Transactions.
  4.  
  5. Click on a transaction

Connect NEAR to Calimero

Conclusion

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.

Latest from Calimero