Auto-wrapping of SNIP-20 tokens with IBC Hooks
A step-by-step guide on how to auto-wrap SNIP-20 tokens with IBC hooks.
Tutorial: Auto-wrapping of SNIP-20 Tokens
In this tutorial, you will learn how to use IBC hooks to auto-wrap SNIP-20 tokens between two LocalSecret IBC chains. Simply put, you will learn how to IBC transfer tokens from one blockchain to another blockchain, and in doing so, the token transfer will execute a smart contract call that turns the tokens into privacy-preserving tokens, all with a single token transfer!
Overview
What You Will Learn: This tutorial is structured to cover the following key steps:
Setting up a Hermes relayer between two LocalSecret chains, specifically Chain secretdev-1 and Chain secretdev-2.
Executing an IBC token transfer between the two aforementioned chains.
Uploading and initializing a SNIP-20 contract on the secretdev-1 chain.
Uploading and initializing a Wasm Hooks wrapper contract on the secretdev-1 chain.
Transferring tokens from secretdev-1 to secretdev-2, and in the process, utilizing IBC hooks to automatically wrap the SNIP-20 tokens.
Let's dive in! 🏊♀️
Set up Hermes Relayer
To follow along with this tutorial, setup a Hermes relayer between two LocalSecret chains using the Secret IBC setup documentation. Once you have established an IBC transfer channel, you are ready to proceed to the next step.
Execute IBC Token Transfer
In order to auto-wrap SNIP-20 tokens over IBC, you must first instantiate a SNIP-20 smart contract on LocalSecret with the IBC denom of the token.
Want to learn more about IBC denoms? Read the Cosmos documentation here.
You can find the IBC denom of your token by executing an IBC token transfer. Assuming you have funded the LocalSecret wallet 'a'
for chain secretdev-1, run the following:
If you have never funded a Hermes wallet or LocalSecret wallet before, learn how to do so here.
If you would like to do further reading, refer to the LocalSecret wallet docs and the Hermes wallet docs.
Query that the transaction was successful:
Now switch to the destination network (secretdev-2) and query the bank balance of wallet 'a'
to confirm that the transaction was successful:
Congrats 🎉 You should now see the ibc-denom returned in the transaction query:
SNIP-20 Contract
Now, let's upload the SNIP-20 contract and instantiate it with the correct IBC denom. cd
into ./contracts/snip20-reference-impl and then compile the contract:
Now upload it (but first make sure you are on chain secretdev-1):
Query that the upload was successful:
If the upload was successful it should return:
Lastly, instantiate the contract with your associated IBC denom:
Query successful instantiation:
If the instantiation was successful, it will return:
Wasm Hooks Contract
Now let's upload and instantiate the wasm hooks contract👍First, cd
into ./contracts/ibc-hooks-contract
Upload:
Query successful upload:
Upon successful upload it will return:
Instantiate:
Query successful instantiation:
If the instantiation was successful it will return:
Auto-wrap Tokens
Now all that's left is to make an IBC token transfer and experience the magic of IBC hooks with the token wrapping contract.
First, initialize the variables in your terminal:
Now execute the token transfer!
Query that it was successful:
Here is an excerpt from the transaction query which includes the IBC memo:
Notice that the sender is wallet address 'a'
and the receiver is the SNIP-20 contract address.
Congrats! You've just successfully used IBC hooks to auto-wrap tokens on Secret Network 🎉🚀
Last updated