githubEdit

Sending Messages

Learn how to send messages with SecretJS.

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 Messages

On a signer secret.js, secretjs.tx is used to broadcast transactions. Every function under secretjs.tx can receive an optional TxOptionsarrow-up-right.

Full API Β»arrow-up-right

secretjs.tx.broadcast()arrow-up-right

Used to send a complex transactions, which contains a list of messages. The messages are executed in sequence, and the transaction succeeds if all messages succeed.

For a list of all messages see: https://secretjs.scrt.network/interfaces/Msgarrow-up-right

const addMinterMsg = new MsgExecuteContract({
  sender: MY_ADDRESS,
  contract_address: MY_NFT_CONTRACT,
  code_hash: MY_NFT_CONTRACT_CODE_HASH, // optional but way faster
  msg: { add_minters: { minters: [MY_ADDRESS] } },
  sent_funds: [], // optional
});

const mintMsg = new MsgExecuteContract({
  sender: MY_ADDRESS,
  contract_address: MY_NFT_CONTRACT,
  code_hash: MY_NFT_CONTRACT_CODE_HASH, // optional but way faster
  msg: {
    mint_nft: {
      token_id: "1",
      owner: MY_ADDRESS,
      public_metadata: {
        extension: {
          image: "https://scrt.network/secretnetwork-logo-secondary-black.png",
          name: "secretnetwork-logo-secondary-black",
        },
      },
      private_metadata: {
        extension: {
          image: "https://scrt.network/secretnetwork-logo-primary-white.png",
          name: "secretnetwork-logo-primary-white",
        },
      },
    },
  },
  sent_funds: [], // optional
});

const tx = await secretjs.tx.broadcast([addMinterMsg, mintMsg], {
  gasLimit: 200_000,
});

secretjs.tx.simulate()arrow-up-right

Used to simulate a complex transactions, which contains a list of messages, without broadcasting it to the chain. Can be used to get a gas estimation or to see the output without actually committing a transaction on-chain.

The input should be exactly how you'd use it in secretjs.tx.broadcast(), except that you don't have to pass in gasLimit, gasPriceInFeeDenom & feeDenom.

Notes:

  • On mainnet, it's recommended to not simulate every transaction as this can burden your node provider. Instead, use this while testing to determine the gas limit for each of your app's transactions, then in production use hard-coded values.

  • Gas estimation is known to be a bit off, so you might need to adjust it a bit before broadcasting.

  • MsgInstantiateContract, MsgExecuteContract, MsgMigrateContract, MsgUpdateAdmin & MsgClearAdmin simulations are not supported for security reasons.

secretjs.tx.signTx()arrow-up-right

Used to sign transactions independently from the broadcast process. This is useful when you want to keep your seed safe and sign transactions offline.

secretjs.tx.broadcastSignedTx()arrow-up-right

Used to send offline signed transactions.

secretjs.tx.authz.exec()arrow-up-right

MsgExec attempts to execute the provided messages using authorizations granted to the grantee. Each message should have only one signer corresponding to the granter of the authorization.

Input: MsgExecParamsarrow-up-right

secretjs.tx.authz.exec.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.authz.grant()arrow-up-right

MsgGrant is a request type for Grant method. It declares authorization to the grantee on behalf of the granter with the provided expiration time.

Input: MsgGrantParamsarrow-up-right

secretjs.tx.authz.grant.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.authz.revoke()arrow-up-right

MsgRevoke revokes any authorization with the provided sdk.Msg type on the granter's account with that has been granted to the grantee.

Input: MsgRevokeParamsarrow-up-right

secretjs.tx.authz.revoke.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.bank.multiSend()arrow-up-right

MsgMultiSend represents an arbitrary multi-in, multi-out send message.

Input: MsgMultiSendParamsarrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.bank.send()arrow-up-right

MsgSend represents a message to send coins from one account to another.

Input: MsgSendParamsarrow-up-right

secretjs.tx.bank.send.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.compute.storeCode()arrow-up-right

Upload a compiled contract to Secret Network

Input: MsgStoreCodeParamsarrow-up-right

secretjs.tx.compute.storeCode.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.compute.instantiateContract()arrow-up-right

Instantiate a contract from code id

Input: [MsgInstantiateContractParams](https://secretjs.scrt.network/interfaces/MsgInstantiarrow-up-right

ateContractParams)

secretjs.tx.compute.instantiateContract.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

WARNING: secretjs.tx.compute simulations are not supported for security reasons.

secretjs.tx.compute.executeContract()arrow-up-right

Execute a function on a contract

Input: MsgExecuteContractParamsarrow-up-right

secretjs.tx.compute.executeContract.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

WARNING: secretjs.tx.compute simulations are not supported for security reasons.

secretjs.tx.compute.migrateContract()arrow-up-right

Migrate a contract's code while keeping the same address. Invokes the migrate() function on the new code.

Input: MsgMigrateContractParamsarrow-up-right

secretjs.tx.compute.migrateContract.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

WARNING: secretjs.tx.compute simulations are not supported for security reasons.

secretjs.tx.compute.updateAdmin()arrow-up-right

Update a contract's admin.

Input: MsgUpdateAdminParamsarrow-up-right

secretjs.tx.compute.updateAdmin.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

WARNING: secretjs.tx.compute simulations are not supported for security reasons.

secretjs.tx.compute.clearAdmin()arrow-up-right

clear a contract's admin.

Input: MsgClearAdminParamsarrow-up-right

secretjs.tx.compute.clearAdmin.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

WARNING: secretjs.tx.compute simulations are not supported for security reasons.

secretjs.tx.crisis.verifyInvariant()arrow-up-right

MsgVerifyInvariant represents a message to verify a particular invariance.

Input: MsgVerifyInvariantParamsarrow-up-right

secretjs.tx.crisis.verifyInvariant.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.distribution.fundCommunityPool()arrow-up-right

MsgFundCommunityPool allows an account to directly fund the community pool.

Input: MsgFundCommunityPoolParamsarrow-up-right

secretjs.tx.distribution.fundCommunityPool.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.distribution.setWithdrawAddress()arrow-up-right

MsgSetWithdrawAddress sets the withdraw address for a delegator (or validator self-delegation).

Input: MsgSetWithdrawAddressParamsarrow-up-right

secretjs.tx.distribution.setWithdrawAddress.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.distribution.withdrawDelegatorReward()arrow-up-right

MsgWithdrawDelegatorReward represents delegation withdrawal to a delegator from a single validator.

Input: MsgWithdrawDelegatorRewardParamsarrow-up-right

secretjs.tx.distribution.withdrawDelegatorReward.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.distribution.withdrawValidatorCommission()arrow-up-right

MsgWithdrawValidatorCommission withdraws the full commission to the validator address.

Input: MsgWithdrawValidatorCommissionParamsarrow-up-right

Or a better one:

secretjs.tx.distribution.withdrawValidatorCommission.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.evidence.submitEvidence()arrow-up-right

MsgSubmitEvidence represents a message that supports submitting arbitrary evidence of misbehavior such as equivocation or counterfactual signing.

Input: MsgSubmitEvidenceParamsarrow-up-right

secretjs.tx.evidence.submitEvidence.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.feegrant.grantAllowance()arrow-up-right

MsgGrantAllowance adds permission for Grantee to spend up to Allowance of fees from the account of Granter.

Input: MsgGrantAllowanceParamsarrow-up-right

secretjs.tx.feegrant.grantAllowance.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.feegrant.revokeAllowance()arrow-up-right

MsgRevokeAllowance removes any existing Allowance from Granter to Grantee.

Input: MsgRevokeAllowanceParamsarrow-up-right

secretjs.tx.feegrant.revokeAllowance.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.gov.deposit()arrow-up-right

MsgDeposit defines a message to submit a deposit to an existing proposal.

Input: MsgDepositParamsarrow-up-right

secretjs.tx.gov.deposit.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.gov.submitProposal()arrow-up-right

MsgSubmitProposal defines an sdk.Msg type that supports submitting arbitrary proposal Content.

Input: MsgSubmitProposalParamsarrow-up-right

secretjs.tx.gov.submitProposal.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.gov.vote()arrow-up-right

MsgVote defines a message to cast a vote.

Input: MsgVoteParamsarrow-up-right

secretjs.tx.gov.vote.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.gov.voteWeighted()arrow-up-right

MsgVoteWeighted defines a message to cast a vote, with an option to split the vote.

Input: MsgVoteWeightedParamsarrow-up-right

secretjs.tx.gov.voteWeighted.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.ibc.transfer()arrow-up-right

MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between ICS20 enabled chains. See ICS Spec here: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structuresarrow-up-right

Input: MsgTransferParamsarrow-up-right

secretjs.tx.ibc.transfer.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.slashing.unjail()arrow-up-right

MsgUnjail defines a message to release a validator from jail.

Input: MsgUnjailParamsarrow-up-right

secretjs.tx.slashing.unjail.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.staking.beginRedelegate()arrow-up-right

MsgBeginRedelegate defines an SDK message for performing a redelegation of coins from a delegator and source validator to a destination validator.

Input: MsgBeginRedelegateParamsarrow-up-right

secretjs.tx.staking.beginRedelegate.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.staking.createValidator()arrow-up-right

MsgCreateValidator defines an SDK message for creating a new validator.

Input: MsgCreateValidatorParamsarrow-up-right

secretjs.tx.staking.createValidator.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.staking.delegate()arrow-up-right

MsgDelegate defines an SDK message for performing a delegation of coins from a delegator to a validator.

Input: MsgDelegateParamsarrow-up-right

secretjs.tx.staking.delegate.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.staking.editValidator()arrow-up-right

MsgEditValidator defines an SDK message for editing an existing validator.

Input: MsgEditValidatorParamsarrow-up-right

secretjs.tx.staking.editValidator.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

secretjs.tx.staking.undelegate()arrow-up-right

MsgUndelegate defines an SDK message for performing an undelegation from a delegate and a validator

Input: MsgUndelegateParamsarrow-up-right

secretjs.tx.staking.undelegate.simulate()arrow-up-right

Simulates execution without sending a transactions. Input is exactly like the parent function. For more info see secretjs.tx.simulate()arrow-up-right.

Last updated

Was this helpful?