The Fadroma Guide
Homepage Documentation Github NPM

Secret Network

Fadroma's support for Secret Network is achieved in this package, by implementing the core Fadroma Agent API (Chain, Agent, Bundle), as well as SN-specific amenities on top of it (such as a Snip20 token client and a ViewingKeyClient).

import { Scrt } from '@fadroma/connect'
import { Devnet } from '@hackbg/fadroma'
import assert from 'node:assert'


Several options are exposed as environment variables.

const config = new Scrt.Config()
ScrtConfig property Env var Description
agentName FADROMA_SCRT_AGENT_NAME agent name
agentMnemonic FADROMA_SCRT_AGENT_MNEMONIC agent mnemonic for scrt only
mainnetChainId FADROMA_SCRT_MAINNET_CHAIN_ID chain id for mainnet
testnetChainId FADROMA_SCRT_TESTNET_CHAIN_ID chain id for mainnet

Connecting and authenticating

To connect to Secret Network with Fadroma, use one of the following:

const mainnet = Scrt.Chain.mainnet({ url: 'test' })
const testnet = Scrt.Chain.testnet({ url: 'test' })
const devnet  = new Devnet({ platform: 'scrt_1.9' }).getChain(Scrt.Chain)
const mocknet = Scrt.Chain.mocknet({ url: 'test' })

This will give you a Scrt instance (subclass of Chain):

import { Chain } from '@fadroma/agent'
for (const chain of [mainnet, testnet]) {
  assert.ok(chain instanceof Chain && chain instanceof Scrt.Chain)

To interact with Secret Network, you need to authenticate as an Agent:

Fresh wallet

This gives you a randomly generated mnemonic.

const agent0 = await mainnet.getAgent().ready
assert.ok(agent0 instanceof Scrt.Agent)
assert.ok(agent0.chain instanceof Scrt.Chain)

The mnemonic property of Agent will be hidden to prevent leakage.

By mnemonic

const agent1 = await mainnet.getAgent({ mnemonic: '...' }).ready

ok(agent1 instanceof Scrt.Agent)
ok(agent1.chain instanceof Scrt.Chain)


// TODO:
// const agent2 = await mainnet.fromKeplr().ready
// ok(agent2 instanceof Scrt.Agent)
// ok(agent2.chain instanceof Scrt.Chain)
// ok(agent2.mnemonic)
// ok(agent2.address)


// TODO:
// const agent3 = await mainnet.fromSecretCli()
// ok(agent3 instanceof Scrt.Agent)
// ok(agent3.chain instanceof Scrt.Chain)
// ok(agent3.mnemonic)
// ok(agent3.address)


The SecretJS module used by a ScrtChain is available on the SecretJS property.

for (const chain of [mainnet, testnet, devnet, mocknet]) {
  await chain.api

  // FIXME: need mock
  //await chain.block
  //await chain.height

  // FIXME: rejects with "#<Object>" ?!
  // await chain.getBalance('scrt', 'address')
  // await chain.getLabel()
  // await chain.getCodeId()
  // await chain.getHash()
  // await chain.fetchLimits()

  // FIXME: Queries should be possible without an Agent.

The api, wallet, and encryptionUtils properties of ScrtAgent expose the SecretNetworkClient, Wallet, and EncryptionUtils (EnigmaUtils) instances.

await agent1.ready
const agent    = agent0
const address  = 'some-addr'
const codeHash = 'some-hash'


@fadroma/scrt exports a Snip20 client class with most of the SNIP-20 methods exposed.

const token = new Scrt.Snip20({ agent, address, codeHash })

There is also a Snip721 stub client. See #172 if you want to contribute a SNIP-721 client implementation:

const nft = new Scrt.Snip721({ agent, address, codeHash })

Viewing keys

@fadroma/scrt exports the ViewingKeyClient class.

const client = new Scrt.ViewingKeyClient({ agent, address, codeHash })

This is meant for embedding into your own Client classes for contracts that implement the SNIP20-compatible viewing key API.

class MyClient extends Client {
  get vk () { return new Scrt.ViewingKeyClient(this) }

Each Snip20 instance already has a vk property that is a ViewingKeyClient.

assert(token.vk instanceof Scrt.ViewingKeyClient)

This is an example of composing client APIs by ownership rather than inheritance, as shown above.

Query permits

// TODO add docs

import { ok } from 'node:assert'
import { Client } from '@fadroma/agent'
import './Scrt.test.ts'