Introduction

Getting started

Check basic token information. Provide the address of chosen token contract and click "Load".

Token Info

Data loading...

Side note: In the code examples down the page, we'll use contractAddress and contractCodeHash variables. You can access both of them in the developer console. Take a small break and give it a try!

const contractAddress = "null" const contractCodeHash = "null"

Remember! They are based on the token contract address you provided at the very top of this page.

Installation

If you want your website to communicate with the Secret Network, you'll need a client set up to connect to the blockchain.

Let's assume we need to add the client to the website. We'll use an example provided in the official documentation. It shows how to configure a gRPC client to Secret Network.

First, we'll install the NPM package, which includes Secret Network JS SDK:

npm install secretjs@beta # OR yarn add secretjs@beta

Now, we can initialise the client. We'll need the Keplr browser extension to sign transactions and access control permits. Of course, we also need to know which network we'd like to connect to. Check out the example below:

import { SecretNetworkClient } from "secretjs"; // Connection data is available on this page: // https://docs.scrt.network/docs/development/api-endpoints // We'll go ahead with the testnet connection const grpcWebUrl = "https://testnet-web-rpc.roninventures.io"; const chainId = "pulsar-2"; // A client with Keplr integration — Keplr is the signer await window.keplr.enable(chainId) const [{ address: myAddress }] = await keplrOfflineSigner.getAccounts() const secretClient = await SecretNetworkClient.create({ grpcWebUrl, chainId, wallet: window.getOfflineSignerOnlyAmino(chainId), walletAddress: myAddress, encryptionUtils: window.getEnigmaUtils(chainId), })

This website has one up and running. You can check it in the developer console. Just type secretClient and see what it's got for you!

Reading data

SNIP-20 Queries

Below you'll find so-called authenticated queries. It means that the contract has to know who sent the query to apply access control correctly. We'll use permits to prove who we are.

Get Balance

Returns the balance of the given address. Returns 0 if the address is unknown to the contract.

await secretClient.query.snip20.getBalance({ address: secretClient.address, contract: { address: contractAddress, codeHash: contractCodeHash }, auth: { permit: await getPermit() }})

Copy-paste the code snippet into the developer console, or use the form below:

Get Transfer History

Returns a list of transfers made by the querying address in the newest-first order. The user may optionally specify a limit on the number of transfers returned by paging the available items.

await secretClient.query.snip20.getTransferHistory({ address: secretClient.address, contract: { address: contractAddress, codeHash: contractCodeHash }, auth: { permit: await getPermit() }, page_size: PAGE_SIZE })

Copy-paste the code snippet into the developer console, or use the form below:

Get Transaction History

Returns a list of transactions made by the querying address in the newest-first order. The user may optionally specify a limit on the number of transactions returned by paging the available items.

await secretClient.query.snip20.getTransactionHistory({ address: secretClient.address, contract: { address: contractAddress, codeHash: contractCodeHash }, auth: { permit: await getPermit() }, page_size: PAGE_SIZE })

Copy-paste the code snippet into the developer console, or use the form below:

Get Allowance

Returns the number of tokens delegated by the owner to the spender. It's a similar feature to the ERC-20 allowances.

await secretClient.query.snip20.GetAllowance({ contract: { address: contractAddress, codeHash: contractCodeHash }, owner: secretClient.address, // spender address, i.e. Bob, spender: "secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne", auth: { permit: await getPermit() } })

Copy-paste the code snippet into the developer console, or use the form below:

Writing data

SNIP-20 Transactions

Every single transaction has to be signed by to be executed.

Send

Moves amount from the sender account to the recipient account. The receiver account MAY be a contract which got registered with the RegisterReceive message.

await secretClient.tx.snip20.send({ sender: secretClient.address, contractAddress: contractAddress, codeHash: contractCodeHash, msg: { send: { // recepient address, i.e. Bob, recipient: "secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne", // amount to be sent amount: "30000000", }, }}, { gasLimit: 5_000_000 })

Copy-paste the code snippet into the developer console, or use the form below:

Transfer

Moves tokens from the account that appears in the Cosmos message sender field to the account in the recipient field. This is where allowances make sense!

await secretClient.tx.snip20.transfer({ sender: secretClient.address, contractAddress: contractAddress, codeHash: contractCodeHash, msg: { transfer: { // recepient address, i.e. Bob, recipient: "secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne", // amount to be transferred amount: "30000000", }, }}, { gasLimit: 5_000_000 })

Copy-paste the code snippet into the developer console, or use the form below:

Increase Allowance

Set or increase the allowance so the spender can access up to current_allowance + amount tokensfrom the Cosmos message sender account. This may optionally come with an expiration time, which if set limits when the approval can be used (by time).

await secretClient.tx.snip20.increaseAllowance({ sender: secretClient.address, contractAddress: contractAddress, codeHash: contractCodeHash, msg: { increase_allowance: { // spender address, i.e. Bob, spender: "secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne", // amount to be added to the current allowance amount: "30000000", }, }}, { gasLimit: 5_000_000 })

Copy-paste the code snippet into the developer console, or use the form below:

Decrease Allowance

Decrease or clear the allowance by a sent amount. The message can include an expiration time.

await secretClient.tx.snip20.decreaseAllowance({ sender: secretClient.address, contractAddress: contractAddress, codeHash: contractCodeHash, msg: { decrease_allowance: { // spender address, i.e. Bob, spender: "secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne", // amount to be subtracted from the current allowance amount: "30000000", }, }}, { gasLimit: 5_000_000 })

Copy-paste the code snippet into the developer console, or use the form below: