Examples

Usage examples of the Nomos SDK

Sending funds

For this proposal to work, the multisig must have a balance x >= amount sent.

const {transactionHash, proposal} = await multisig.createProposal({
  from: "<sender address>",
  description: "<proposal description<",
  messages: [
    {
      bank: {
        send: {
          amount: [
            {
              denom: "<network denom>", //"aarch" in archway mainnet
              amount: "<amount to send",
            },
          ],
          to_address: receiverAddr,
        },
      },
    },
  ],
});

Instantiate any contract

To instantiate any contract you must pass the correct instantiateMessage that creates the contract. Then encode it base64 and create a wasm.instantiate message.

//this object depends on the contract to instantiate
let instantiateMessage = JSON.stringify({});
let msgBin = Buffer.from(instantiateMessage).toString("base64");

const {proposal, transactionHash} = await multisig.createProposal({
  from: "<sender address>",
  description: "<proposal description>",
  messages: [
    {
      wasm: {
        instantiate: {
          admin: "<admin of contract>,
          code_id: <contract codeID>,
          funds: [],
          label: "<contract label>",
          msg: msgBin,
        },
      },
    },
  ],
});

Transfer CW20 tokens

Any contract related transaction should have the message to send wrapped inside a wasm.execute. On this example we create a message to transfer 1 CW20 token with 18 decimal places.

const msg = Buffer.from(
  JSON.stringify({
    transfer: {
      amount: new BigNumber("1").multipliedBy(new BigNumber("1e18")),
      recipient: "<receiver address>",
    },
  })
).toString("base64");

const {proposal, transactionHash} = await multisig.createProposal({
  from: "<sender address>",
  description: "<proposal description",
  messages: [
    {
      wasm: {
        execute: {
          contract_addr: "<cw20 contract address>",
          msg,
          funds: [],
        },
      },
    },
  ],
});

Stake native tokens

A staking message is a special type of message that isnt wrapped in the commin wasm.execute. It can have different types, here we expose as example the delegate staking.

const {transactionHash, proposal} = await multisig.createProposal({
  from: "<sender address>",
  description: "<proposal description>",
  manualExecution: false,
  messages: [
    {
      staking: {
        delegate: {
          amount: {
            denom: "<network denom>",
            amount: "<amount>",
          },
          validator: validatorAddr,
        },
      },
    },
  ],
});
//TO WITHDRAW TOKENS, these can have a withdraw period depending on the network
//{
  //staking: {
    //undelegate: {
      //amount: {
        //denom: network.stakeCurrency.coinMinimalDenom,
        //amount: amount,
      //},
      //validator: validatorAddr,
    //},
  //},
//},

Astrovault deposit

An example of contract interaction is the astrovault deposit, astrovault is an Automated Market Maker living on the archway blockchain.

const amount = new BigNumber("<tokens amount>").multipliedBy(new BigNumber("1e18")).toString();
const msg = Buffer.from(
  JSON.stringify({
    deposit: {
      assets_amount: [amount, "0"],
      direct_staking: {},
    },
  })
).toString("base64");

const {proposal} = await multisig.createProposal({
  description: `Deposit ${amount} arch on astrovault`,
  from: userAddress,
  messages: [
    {
      wasm: {
        execute: {
          contract_addr: vault,
          msg,
          funds: [
            {
              amount,
              denom: network.stakeCurrency.coinMinimalDenom,
            },
          ],
        },
      },
    },
  ],
});

Astrovault Withdraw

const amount = new BigNumber("<withdraw amount>").multipliedBy(new BigNumber("1e18")).toString();
const msg = Buffer.from(
  JSON.stringify({
    withdrawal: {
      amount: new BigNumber(amount).div(new BigNumber("1e12")),
      direct_pool_withdrawal: {
        stable: {
          withdrawal_lockup_assets_amount: [amount, "0"],
          is_instant_withdrawal: true,
          to: contractAddress,
        },
      },
    },
  })
).toString("base64");

const {proposal} = await multisig.createProposal({
  description: `Deposit ${amount} arch on astrovault`,
  from: userAddress,
  messages: [
    {
      wasm: {
        execute: {
          contract_addr: pool,
          msg,
          funds: [],
        },
      },
    },
  ],
});

Last updated