Secret Network
WebsiteDiscordGithub
  • 👋INTRODUCTION
    • Secret Network Introduction
    • Secret Network Techstack
      • Private transactions - A quick summary
      • Blockchain Technology
        • Cosmos Basics
        • Tendermint
        • Cosmos SDK
        • IBC
        • CosmWasm
      • Privacy Technology
        • Encryption - Key Management
          • Overview
          • Key Derivation & Encryption Techniques
          • The Initialization Of Secret Network
          • Full Node Boostrap
          • Contract State Encryption
          • Transaction Encryption
          • Consensus seed rotation
        • Trusted Execution Environments  (TEE) —  Intel SGX
          • How Secret Network Uses SGX
          • SGX-SPS Security & Reliabillity
          • Remote Attestation
          • Trusted & Untrusted Core
          • Sealing
        • Private smart contracts - overview
  • 💻Development
    • 🏠Getting Started
      • Setting Up Your Environment
        • Cargo.toml Best Practices (Crates vs Dependencies)
      • Compile and Deploy
      • Running the Application
      • Compile and Deploy on Secret testnet (best for Javascript devs)
      • Fullstack dApp Integration
    • 🤓Secret Contracts
      • Secret Contracts & CosmWasm
        • Framework overview
        • Secret Contract Components
          • Instantiation Message
          • Execution Message
          • Query Message
          • Deps/DepsMut
          • Storage
            • Prefixed Storage
            • Singleton
            • Keymap
            • Append Store
            • Best practices
        • CosmWasm vs Secret CosmWasm
      • Secret Tokens (SNIP-20)
      • Contract - module call
      • Secret contract - Design Space/Features
        • Secret Contracts introduction
        • Gas/Fee usage
        • TPS and scalability
        • Privacy Essentials
        • Access Control
          • Viewing Keys
          • Permits
        • Trusted and untrusted data
        • Secret-VRF - on-chain Randomness
        • Privacy design
          • Mitigate privacy risks - full guide
          • Gas Evaporation & Tracking
        • Confidential Computing Layer
        • Fiat/Crypto Onboarding
        • Account abstraction
        • Fee abstraction
        • Wallet support
        • Bridge (messaging/tokens)
        • IBC (Hooks, PFM, Wasm)
        • Price Oracles
        • Auto Restaking
      • Permissioned Viewing
        • Viewing Keys
        • Permits
      • Cross Contract Communication
      • Submessages
        • get_contract_code_hash
      • Randomness API - Secret VRF
        • Native On-chain randomness
        • Randomness over IBC
      • Execution Finalization
      • Factory Contracts
      • Contract Migration
        • Manual - < v1.11
        • Native - from v1.11
      • Cross-deploy Vanilla CW and Secret Contracts
      • Testing Secret Contracts
        • Unit Tests
        • Continuous Integration
        • Datatype Handling - Uint, floats etc.
    • 👀Secret Contract - Reference, Guides, Examples
      • Starter guide - Millionaire's Problem
      • Reference Contracts
      • Open source dApps
      • Tools & Libraries
        • Network interaction SDKs
          • Secret.js (JavaScript)
          • SecretPy (Python)
          • SecretK (Kotlin)
          • Secret.NET
            • Snippets
              • Deploying a Contract
              • Send Native Coin
              • Query a Contract
              • Create a new Wallet
              • Permits
              • SNIP20
              • SNIP721
          • Shade.Js
        • LocalSecret - Devnet docker
        • Smart contract - Tools/Utils
          • Secret Toolkit
          • CW-Plus
          • Fadroma - SC framework
          • Hidden Gems
          • Other
            • Secret IDE
            • Polar
    • 🖼️Frontend Development
      • Getting Started with SecretJS
        • Usage Examples
          • Sending Queries
          • Sending Messages
          • Contract Migration
          • Wallet Integrations
          • Query Permits
          • SNIP20 (SCRT Tokens)
          • SNIP721 (Secret NFTs)
      • Feegrant
        • Understanding Feegrant allowances
        • Grant allowances
        • Using grant allowances to execute transactions
        • Using the Fee Grant Faucet
    • 📬Deployment Addresses/ API Endpoints
      • Secret (SNIP 20) token contracts list
        • SNIP Asset naming guidelines
      • Connecting to the Network
        • API Endpoints Mainnet (Secret-4)
        • API Endpoints Testnet (Pulsar-3)
        • Usage examples
        • Comparison of endpoint types
      • Create your own SNIP-25 IBC Token
  • Secret AI
    • 🤝Introduction
    • 🏗️Architecture
    • 👩‍💻Secret AI SDK
      • Setting Up Your Environment
      • Running the Application
    • 🪙Economics
    • Smart Contract Reference
      • SubscriptionManager
      • WorkerManager
      • RewardsManager
  • 🌐SecretVM - Confidential Virtual Machines
    • 🤝Introduction
    • 🏗️Architecture
    • ☑️Attestation
      • What is Attestation
      • Obtaining Attestation Data
      • Attestation Report - Key Fields
      • Chain of Trust
    • 🏁Launching a SecretVM
    • 🛠️Managing SecretVM Lifecycle
    • ✅Verifying a SecretVM
      • 🐢Full Verification
      • 🐰Quick Verification
    • 💡Best Practices for Developers
    • 📖Glossary
  • 🔓Confidential Computing Layer
    • 🧑‍🚀IBC Developer Toolkit
      • Basics
        • Overview
        • Cross-chain Messaging with IBC Hooks
          • Functions, Methods, and Data Structures
          • Typescript SDK
          • IBC-Hooks
        • IBC Relaying with Go Relayer
      • Usecases
        • Storing Encrypted Data on Secret Network
          • Key-Value store Developer Tutorial
        • Secret VRF for IBC with IBC-Hooks
        • Confidential Voting
        • Sealed Bid Auctions
      • Supported Networks
        • Mainnet
        • Testnet
    • 🤝Ethereum (EVM) Developer Toolkit
      • Basics
        • Overview
        • Connecting Metamask to Secret Network
        • SecretPath + Reown integration
        • Cross-chain Messaging
          • SecretPath
            • Architecture Overview
            • Detailed Architecture
            • SecretPath Developer Tutorials
            • Public EVM Gateway Architecture
            • How to deploy SecretPath on your chain
          • Axelar GMP
            • Architecture Overview
            • Axelar GMP Developer Tutorial
      • Usecases
        • Storing Encrypted Data on Secret Network
          • Key-Value store Developer Tutorial
        • Sealed Bid Auction
          • Sealed Bid Auction Developer Tutorial
        • Confidential Voting
          • Confidential Voting Developer Tutorial with SecretPath
        • VRF
          • Implementing VRF into any EVM Contract
          • VRF Developer Tutorial
          • Performance figures of SecretVRF vs competitors
          • Using encrypted payloads for VRF
          • Converting from Chainlink VRF to Secret VRF in four steps
        • Confidential Document Sharing
        • Tokens
          • From EVM to Secret
      • Supported Networks
        • EVM
          • EVM Mainnet
          • EVM Testnet
          • Gateway Contract ABI
        • Secret Gateway
          • SecretPath mainnet (secret-4) contracts
          • SecretPath testnet (pulsar-3) contracts
    • 🙌Solana Developer Toolkit
      • Usecases
        • Storing Encrypted Data on Secret Network
          • Key-value Store Developer Tutorial
        • VRF
          • VRF Developer Tutorial
      • Program IDs
        • Solana Mainnet & Testnet
        • Gateway Contract IDL
  • 🤫Overview, Ecosystem and Technology
    • 🚀Secret Network Overview
      • The SCRT coin
      • Private Tokens
      • Use Cases
        • Decentralized Finance (DeFi)
        • Art And Digital Media
        • Gaming
        • Data Privacy
        • Payments And Transactions
        • Communication
      • The technology
      • History
      • Roadmap (Core development)
        • Secret 2.0
      • Where To Buy SCRT?
      • Using the Testnet
    • 🐸Ecosystem Overview
      • Wallets
      • Applications
      • Explorers & tools
      • Funding
        • SCRT Labs Grants
        • Dilutive funding/VC raise
        • Community Pool
        • Developer bounties
          • SCRT Labs bounties [on-hold]
          • CCBL [on-hold]
          • CCR [On-hold]
        • Application specific
          • Shade Grants
      • Contributors & Entities
        • Validators
        • SCRT Labs
        • Secret Foundation
        • Secret Committees
          • Support
          • Governance
      • Secret Network Dictionary
  • 🔧Infrastructure
    • 🔓Use SecretCLI
      • Secretcli vs. Secretd
      • Install
      • Configuration
      • Address Types
      • Key Types
      • Generating Keys
      • Viewing Keys
      • Query Transactions
      • Send Tokens
      • Multisig Keys
      • Multisig Transactions
      • Transaction Broadcasting
      • Fees & Gas
      • Fee Distribution
      • Secret Contracts
      • Slashing
      • Minting
      • Delegating
      • Restake
      • Nodes
      • Governance
        • Creating Governance Proposals
        • Query Proposals
        • Deposits
        • Voting
    • 🔐Use Ledger hardware wallet
      • 🔐Ledger with SecretCLI
    • 🖥️Running a node/validator
      • Setting up a node/validator
        • Hardware setup
          • Hardware Compliance
          • VPS/Bare-Metal Compliance
            • Leaseweb Setup
            • PhoenixNAP Setup
            • Psychz Setup
            • nForce Setup
            • Vultr Setup
            • OVHCloud Setup
            • Microsoft Azure Setup
          • Patching your Node
          • Enclave verification
          • Registration troubleshooting
        • Testnet Setup
          • Install SGX
          • Install secretd
          • Setup Full Node
          • Testnet State Sync
          • Becoming a Testnet Validator
          • Installing CLI & Creating A New Address
        • Mainnet Setup
          • Install SGX
          • Install secretd
          • Setup Full Node
          • Quicksync / Snapshot
          • Statesync
          • Becoming A Validator
          • Installing CLI & Creating A New Address
      • Maintaining a node/validator
        • Slashing information
        • Migrating a Validator
        • Troubleshooting
        • Validator Backup
        • Server security
          • SSH authentication
          • Server configuration
          • Uncomplicated-Firewall (UFW)
          • Local CLI
        • Node Monitoring
          • Prometheus
            • Environment Preperation
            • Install Node Exporter
            • Install Prometheus
            • Configuring Prometheus
          • Grafana
            • Install Grafana
            • Grafana Dashboard
            • Next Steps
          • Docker
            • Install Docker
            • Configuration
            • Start Containers
            • Grafana Dashboard
            • Application Ports
            • Stop Containers
          • Goaccess
            • Install Goaccess
            • Setup Goaccess
        • Helpful commands
          • Query Validators
          • Bond Tokens
          • Withdraw Rewards
          • Query Delegations
          • Unbond Tokens
          • Query Unbonding-Delegations
          • Redelegate Tokens
          • Query Redelegations
          • Query Parameters
          • Query Pool
          • Query Delegations To Validator
      • API Noderunning
        • Running Multiple Nodes on the Same Server
        • Node Loadbalancing using Nginx
          • Setup Nginx
          • Example Nginx config
        • Using Auto heal to improve cluster uptime for Nginx
      • Sentry and Archive nodes
        • Mantlemint
        • Sentry Nodes
        • Archive Nodes
    • ⛓️IBC Relayers
      • Hermes
      • RLY
      • IBC channel database
    • 🆙Upgrade Instructions
      • v1.13
      • v1.12
      • v1.11
      • v1.10
      • v1.9
      • v1.8
      • v1.7
      • Shockwave Omega v1.6
      • v1.5
      • Shockwave Delta v1.4
      • Shockwave Delta v1.4 (Testnet)
      • Shockwave Alpha v1.3
      • Cosmovisor
      • Vulcan Network Upgrade (OLD)
    • ☠️Postmortems
      • SNIP-20 leaks
      • xApic
      • Secpk-Verifications Bloat
      • Earn Contract Exploit
      • Testnet Halt 95
    • ✍️Contribute to the documentation
      • Report Bugs
      • Suggest Enhancements
      • First Contribution Guide
      • Pull Request Templates
        • Update Documentation
        • Bug Fix
        • Improve Performance
        • Change Functionality
      • Style Guide
    • 🌊Versioning & Changelog
      • Secret Network v1.13
      • Secret Network v1.12
      • Secret Network v1.11
      • Secret Network v1.10
      • Secret network v1.9
      • Secret Network v1.7/1.8
      • Secret Network v1.6
      • Secret Network v1.5
      • Secret Network v1.4 (CosmWasm 1.0)
Powered by GitBook
On this page
  • Secret Network Client Setup
  • SecretJS Queries

Was this helpful?

Edit on GitHub
Export as PDF
  1. Development
  2. Frontend Development
  3. Getting Started with SecretJS
  4. Usage Examples

Sending Queries

Learn how to send queries with SecretJS.

PreviousUsage ExamplesNextSending Messages

Last updated 3 months ago

Was this helpful?

Secret Network Client Setup

import { SecretNetworkClient, Wallet } from "secretjs";

const wallet = new Wallet("Your mnemonic words go here");

const secretjs = new SecretNetworkClient({
  chainId: "pulsar-3",
  url: "https://pulsar.lcd.secretnodes.com",
  wallet: wallet,
  walletAddress: wallet.address,
});

SecretJS Queries

Returns account details based on address.

const { address, accountNumber, sequence } = await secretjs.query.auth.account({
  address: myAddress,
});

Returns all existing accounts on the blockchain.

/// Get all accounts
const result = await secretjs.query.auth.accounts({});

Queries all x/auth parameters.

const {
  params: {
    maxMemoCharacters,
    sigVerifyCostEd25519,
    sigVerifyCostSecp256k1,
    txSigLimit,
    txSizeCostPerByte,
  },
} = await secretjs.query.auth.params({});

Returns list of authorizations, granted to the grantee by the granter.

Balance queries the balance of a single coin for a single account.

const { balance } = await secretjs.query.bank.balance({
  address: myAddress,
  denom: "uscrt",
});

AllBalances queries the balance of all coins for a single account.

TotalSupply queries the total supply of all coins.

SupplyOf queries the supply of a single coin.

Params queries the parameters of x/bank module.

DenomsMetadata queries the client metadata of a given coin denomination.

DenomsMetadata queries the client metadata for all registered coin denominations.

Get codeHash of a Secret Contract.

Get codeHash from a code id.

Get metadata of a Secret Contract.

Get all contracts that were instantiated from a code id.

Query a Secret Contract

type Result = {
  token_info: {
    decimals: number;
    name: string;
    symbol: string;
    total_supply: string;
  };
};

const result = (await secretjs.query.compute.queryContract({
  contract_address: sScrtAddress,
  code_hash: sScrtCodeHash, // optional but way faster
  query: { token_info: {} },
})) as Result;

Get WASM bytecode and metadata for a code id.

const { codeInfo } = await secretjs.query.compute.code(codeId);

Query all contract codes on-chain.

Get upgrades history of a Secret Contract.

Params queries params of the distribution module.

ValidatorOutstandingRewards queries rewards of a validator address.

ValidatorCommission queries accumulated commission for a validator.

ValidatorSlashes queries slash events of a validator.

DelegationRewards queries the total rewards accrued by a delegation.

DelegationTotalRewards queries the total rewards accrued by a each validator.

DelegatorValidators queries the validators of a delegator.

DelegatorWithdrawAddress queries withdraw address of a delegator.

CommunityPool queries the community pool coins.

DelegatorWithdrawAddress queries withdraw address of a delegator.

Evidence queries evidence based on evidence hash.

AllEvidence queries all evidence.

Allowance returns fee granted to the grantee by the granter.

Allowances returns all the grants for address.

Proposal queries proposal details based on ProposalID.

Proposals queries all proposals based on given status.

// Get all proposals
const { proposals } = await secretjs.query.gov.proposals({
  proposal_status: ProposalStatus.PROPOSAL_STATUS_UNSPECIFIED,
  voter: "",
  depositor: "",
});

Vote queries voted information based on proposalID, voterAddr.

Votes queries votes of a given proposal.

Params queries all parameters of the gov module.

Deposit queries single deposit information based proposalID, depositAddr.

const {
  deposit: { amount },
} = await secretjs.query.gov.deposit({
  depositor: myAddress,
  proposalId: propId,
});

Deposits queries all deposits of a single proposal.

TallyResult queries the tally of a proposal vote.

Channel queries an IBC Channel.

Channels queries all the IBC channels of a chain.

ConnectionChannels queries all the channels associated with a connection end.

ChannelClientState queries for the client state for the channel associated with the provided channel identifiers.

ChannelConsensusState queries for the consensus state for the channel associated with the provided channel identifiers.

PacketCommitment queries a stored packet commitment hash.

PacketCommitments returns all the packet commitments hashes associated with a channel.

PacketReceipt queries if a given packet sequence has been received on the queried chain

PacketAcknowledgement queries a stored packet acknowledgement hash.

PacketAcknowledgements returns all the packet acknowledgements associated with a channel.

UnreceivedPackets returns all the unreceived IBC packets associated with a channel and sequences.

UnreceivedAcks returns all the unreceived IBC acknowledgements associated with a channel and sequences.

NextSequenceReceive returns the next receive sequence for a given channel.

ClientState queries an IBC light client.

ClientStates queries all the IBC light clients of a chain.

ConsensusState queries a consensus state associated with a client state at a given height.

ConsensusStates queries all the consensus state associated with a given client.

Status queries the status of an IBC client.

ClientParams queries all parameters of the ibc client.

UpgradedClientState queries an Upgraded IBC light client.

UpgradedConsensusState queries an Upgraded IBC consensus state.

Connection queries an IBC connection end.

Connections queries all the IBC connections of a chain.

ClientConnections queries the connection paths associated with a client state.

ConnectionClientState queries the client state associated with the connection.

ConnectionConsensusState queries the consensus state associated with the connection.

DenomTrace queries a denomination trace information.

DenomTraces queries all denomination traces.

Params queries all parameters of the ibc-transfer module.

Params returns the total set of minting parameters.

Inflation returns the current minting inflation value.

AnnualProvisions current minting annual provisions value.

Params queries a specific parameter of a module, given its subspace and key.

Returns the key used for transactions.

Returns the key used for registration.

Returns the encrypted seed for a registered node by public key.

Params queries the parameters of slashing module.

SigningInfo queries the signing info of given cons address.

SigningInfos queries signing info of all validators.

Validators queries all validators that match the given status.

// Get all validators
const { validators } = await secretjs.query.staking.validators({ status: "" });

Validator queries validator info for given validator address.

ValidatorDelegations queries delegate info for given validator.

ValidatorUnbondingDelegations queries unbonding delegations of a validator.

Delegation queries delegate info for given validator delegator pair.

UnbondingDelegation queries unbonding info for given validator delegator pair.

DelegatorDelegations queries all delegations of a given delegator address.

DelegatorUnbondingDelegations queries all unbonding delegations of a given delegator address.

Redelegations queries redelegations of given address.

DelegatorValidators queries all validators info for given delegator address.

DelegatorValidator queries validator info for given delegator validator pair.

HistoricalInfo queries the historical info for given height.

Pool queries the pool info.

Parameters queries the staking parameters.

GetNodeInfo queries the current node info.

GetSyncing queries node syncing.

GetLatestBlock returns the latest block.

GetBlockByHeight queries block for given height.

GetLatestValidatorSet queries latest validator-set.

GetValidatorSetByHeight queries validator-set at a given height.

CurrentPlan queries the current upgrade plan.

AppliedPlan queries a previously applied upgrade plan by its name.

UpgradedConsensusState queries the consensus state that will serve as a trusted kernel for the next version of this chain. It will only be stored at the last height of this chain.

ModuleVersions queries the list of module versions from state.

💻
🖼️
secretjs.query.auth.account()
secretjs.query.auth.accounts()
secretjs.query.auth.params()
secretjs.query.authz.grants()
secretjs.query.bank.balance()
secretjs.query.bank.allBalances()
secretjs.query.bank.totalSupply()
secretjs.query.bank.supplyOf()
secretjs.query.bank.params()
secretjs.query.bank.denomMetadata()
secretjs.query.bank.denomsMetadata()
secretjs.query.compute.codeHashByContractAddress()
secretjs.query.compute.codeHashByCodeId()
secretjs.query.compute.contractInfo()
secretjs.query.compute.contractsByCode()
secretjs.query.compute.queryContract()
secretjs.query.compute.code()
secretjs.query.compute.codes()
secretjs.query.compute.contractHistory()
secretjs.query.distribution.params()
secretjs.query.distribution.validatorOutstandingRewards()
secretjs.query.distribution.validatorCommission()
secretjs.query.distribution.validatorSlashes()
secretjs.query.distribution.delegationRewards()
secretjs.query.distribution.delegationTotalRewards()
secretjs.query.distribution.delegatorValidators()
secretjs.query.distribution.delegatorWithdrawAddress()
secretjs.query.distribution.communityPool()
secretjs.query.distribution.foundationTax()
secretjs.query.evidence.evidence()
secretjs.query.evidence.allEvidence()
secretjs.query.feegrant.allowance()
secretjs.query.feegrant.allowances()
secretjs.query.gov.proposal()
secretjs.query.gov.proposals()
secretjs.query.gov.vote()
secretjs.query.gov.votes()
secretjs.query.gov.params()
secretjs.query.gov.deposit()
secretjs.query.gov.deposits()
secretjs.query.gov.tallyResult()
secretjs.query.ibc_channel.channel()
secretjs.query.ibc_channel.channels()
secretjs.query.ibc_channel.connectionChannels()
secretjs.query.ibc_channel.channelClientState()
secretjs.query.ibc_channel.channelConsensusState()
secretjs.query.ibc_channel.packetCommitment()
secretjs.query.ibc_channel.packetCommitments()
secretjs.query.ibc_channel.packetReceipt()
secretjs.query.ibc_channel.packetAcknowledgement()
secretjs.query.ibc_channel.packetAcknowledgements()
secretjs.query.ibc_channel.unreceivedPackets()
secretjs.query.ibc_channel.unreceivedAcks()
secretjs.query.ibc_channel.nextSequenceReceive()
secretjs.query.ibc_client.clientState()
secretjs.query.ibc_client.clientStates()
secretjs.query.ibc_client.consensusState()
secretjs.query.ibc_client.consensusStates()
secretjs.query.ibc_client.clientStatus()
secretjs.query.ibc_client.clientParams()
secretjs.query.ibc_client.upgradedClientState()
secretjs.query.ibc_client.upgradedConsensusState()
secretjs.query.ibc_connection.connection()
secretjs.query.ibc_connection.connections()
secretjs.query.ibc_connection.clientConnections()
secretjs.query.ibc_connection.connectionClientState()
secretjs.query.ibc_connection.connectionConsensusState()
secretjs.query.ibc_transfer.denomTrace()
secretjs.query.ibc_transfer.denomTraces()
secretjs.query.ibc_transfer.params()
secretjs.query.mint.params()
secretjs.query.mint.inflation()
secretjs.query.mint.annualProvisions()
secretjs.query.params.params()
secretjs.query.registration.txKey()
secretjs.query.registration.registrationKey()
secretjs.query.registration.encryptedSeed()
secretjs.query.slashing.params()
secretjs.query.slashing.signingInfo()
secretjs.query.slashing.signingInfos()
secretjs.query.staking.validators()
secretjs.query.staking.validator()
secretjs.query.staking.validatorDelegations()
secretjs.query.staking.validatorUnbondingDelegations()
secretjs.query.staking.delegation()
secretjs.query.staking.unbondingDelegation()
secretjs.query.staking.delegatorDelegations()
secretjs.query.staking.delegatorUnbondingDelegations()
secretjs.query.staking.redelegations()
secretjs.query.staking.delegatorValidators()
secretjs.query.staking.delegatorValidator()
secretjs.query.staking.historicalInfo()
secretjs.query.staking.pool()
secretjs.query.staking.params()
secretjs.query.tendermint.getNodeInfo()
secretjs.query.tendermint.getSyncing()
secretjs.query.tendermint.getLatestBlock()
secretjs.query.tendermint.getBlockByHeight()
secretjs.query.tendermint.getLatestValidatorSet()
secretjs.query.tendermint.getValidatorSetByHeight()
secretjs.query.upgrade.currentPlan()
secretjs.query.upgrade.appliedPlan()
secretjs.query.upgrade.upgradedConsensusState()
secretjs.query.upgrade.moduleVersions()