A Guide on creating a SNIP20 token from scratch

peteblank
4 min readNov 30, 2020

You might be wondering what SNIP20 tokens are. Well they are just like ERC20 tokens, but private and unlike sSCRT they are not interchangeable with secret 1:1. Which means you get to decide the name, symbol, amount and decimals of the SNIP20 token. If you have the know-how, sky is the limit. Yet this article will serve as a HOWTO on creating a basic SNIP20 token.

Before we begin you are going to need install and run the secretcli.. You can install it on Windows, Mac or Linux. I’m using Linux. If you do use Linux you should ideally use Debian or Ubuntu.

To install the secretcli go to https://github.com/enigmampc/SecretNetwork/blob/master/docs/light-client-mainnet.md download the secretcli, then change folders on the terminal to where it is located.

In order to use secretcli you will need to add a ./ before secretcli.

The .deb file should install it on your system but I’m using fedora linux so in my case I used the command

cp secretcli -t /usr/bin

Protip: You might need to try sudo chmod 755 secretcli before using it.

Great, now you’ve downloaded the secretcli. Next, you will need to configure it.

secretcli config chain-id secret-2
secretcli config output json
secretcli config indent true
secretcli config node tcp://secret-2.node.enigma.co:26657
secretcli config trust-node true

Now check the installation.

secretcli status

Next you will be required to create a Secret (SCRT) account (or import your existing one) with Math Wallet. The reason why I’m picking math wallet is because it lets you export the private keys and Mnemonic phrases.

You can get the math wallet at: https://mathwallet.org/

Next on, you will need to type:

secretcli keys add “insert-your-private-key-here’ — recover— legacy-hd-path

add you Mnemonic phrases and password.

To see your private key type.

secretcli keys list

It should appear as name:your account #

Deposit 3 SCRT into your account address just to be sure you have enough gas, you’ll probably use less than that.

Okay now we can begin. Go to https://github.com/enigmampc/SecretNetwork/blob/master/docs/testnet/deploy-contract.md

Download https://github.com/enigmampc/SecretNetwork/releases/download/v0.8.1/contract.wasm.gz

And put it in the same folder as secretcli.

Then type

secretcli tx compute store contract.wasm.gz --from <account #>--gas 2000000 -y

This should store the contract into the secret blockchain. To make sure it got stored properly type:

secretcli query compute list-code
[
...,
{
"id": 12,
"creator": "secret1klqgym9m7pcvhvgsl8mf0elshyw0qhruy4aqxx",
"data_hash": "655CD32C174731A5A06A75F5FCC9B4E76D1556C208454FCB9E0062BA10C98409",
"source": "",
"builder": ""
}
....
]

You should now be able to see your wallet address in the creator field along with the id.

We’re going to make a token call it testsecret and assign it a symbol of tests, with a supply of 1 million and 6 decimals.

Now before we begin you want to make sure the amount is right, so the formula to follow total amount/decimal amount in this case it’d be 1000000/0.000001=1000000000000 because its 1 million divided by 6 decimals.

So type:

secretcli tx compute instantiate <id> — label testsecret‘{“name”: “testsecret”, “symbol”: “TESTS”, “decimals”: 6,”prng_seed”:”cGV0ZQo=’, “initial_balances”: [{“address”:”<wallet address>” , “amount”: “1000000000000”}]}’ — from ‘<account #>’

And that’s it. You have now created the TESTS token on the secret network.

You will need the contract address to add it to your keplr wallet. To find the contract address type:

secretcli query compute list-contract-by-code <code_id>

or check the tx hash with

secretcli q tx <TX_HASH>

Optional: If you want to see the amount you hold you’ll want to create a viewing key, now to create a viewing key type

secretcli tx snip20 create-viewing-key sscrt — from <account> — gas 3000000

The recommended amount for gas is 3 SCRT but don’t worry, you’ll probably spend less than that.

It should give you a tx_hash, now to see the viewing key type:

secretcli q compute tx <tx_hash>

After you do that find the api key

and then type:

secretcli q snip20 balance TESTS<account-address> <viewing-key>

Now to send your TESTS tokens to your keplr wallet type in:

secretcli tx snip20 transfer TESTS<your_secret_wallet_address> <the amount of TESTS you want to send> — from <account number>

If you made a mistake regarding the amounts of tokens you created have no fear. Because this contract also has the mint/burn functionality.

In order to mint more tokens write:

secretcli tx compute execute — label testtokens‘{“mint”:{“amount”: “1000000”, “address”:”<your wallet address>"}}’ — from “<account #>” -y -b block

And to burn

secretcli tx compute execute — label testtokens‘{“burn”:{“amount”: “1000000”, “address”:”<your wallet address>"}}’ — from “<account #>” -y -b block

And that covers everything about how to create a basic snip20 token on the secret network. If I made any mistakes or have any questions feel free to post in the comments section.

--

--