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.
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:
# be on the source network (secretdev-1)secretcliconfignodehttp://localhost:26657# check the initial balance of asecretcliqbankbalancessecret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03# transfer to the destination networksecretclitxibc-transfertransfertransferchannel-0secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s031uscrt--froma
If you have never funded a Hermes wallet or LocalSecret wallet before, learn how to do so here.
Now switch to the destination network (secretdev-2) and query the bank balance of wallet 'a'to confirm that the transaction was successful:
# switch to the destination network (secretdev-2)
secretcli config node http://localhost:36657
# check that you have an ibc-denom
secretcli q bank balances secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03
Congrats 🎉 You should now see the ibc-denom returned in the transaction query:
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: