Secret Tokens (SNIP-20)
Learn how to create a SNIP-20 token on Secret Network
Last updated
Was this helpful?
Learn how to create a SNIP-20 token on Secret Network
Last updated
Was this helpful?
In this tutorial, we are going to create our own SNIP-20 token on Secret Network using Secret Labs' SNIP-20 reference implementation contract, and we will learn how to upload, instantiate, execute, and query our SNIP-20 contract using Secret.js. Let's dive in!
You can clone the source code , which we will reference throughout the course of this documentation.
Use to set up your developer environment.
Now that you've cloned the SNIP-20 reference implementation repo above, let's compile the contract. In your terminal run make build-mainnet-reproducible
.
The compiled wasm file will be output in ./optimized-wasm
.
Now let's upload and instantiate the SNIP-20 Contract. We have already written an for your convenience. If you would like to make any changes to your SNIP-20 token, you can do so .
The initMsg
object in our upload.js
file is referencing the instantiation message defined in . Notice the optional config
variable. If we include config
, there is a variety of additional contract functionality that we could program, such as burn, mint, admin privileges, etc.
Now we are going to instantiate some ZBRA coin. If you want to create your own coin name, update the name, symbol,
and amount
fields respectively.
Otherwise, run node upload:
Upon successful execution, a codeId, contract hash, and contract address will be returned:
To check that the instantiation of our SNIP-20 ZEBRA token was successful, let's query the smart contract's token info.
Run node query_token_info
:
The following is returned upon successful query:
Now let's execute the transfer message with secret.js. Be sure to update the recipient
wallet address with your own wallet before executing the code below. For testing purposes, I am using two Keplr wallet connected to the Secret Network testnet in order to move funds back and forth:
Congrats! You just successfully transferred your own SNIP-20 token on Secret Network! ๐
Now that we have successfully instantiated our SNIP-20 contract, let's send an to better understand the contract's functionality.
Start by adding the token to your Keplr wallet. Click on Keplr, select the hamburger icon, select "Add Token", and then paste in your token's contract address. If you need to fund your wallet to execute the transaction, you can do so using the . You should now see your token in your Keplr wallet!
Let's to another wallet address. The transfer message is defined in msg.rs as follows: