Interacting with Smart Contracts

For interacting with our contracts we first recomend to go to the following sections:

Arch3Js

To interact with our smart contracts, we will use Arch3js which is a JavaScript library that makes it easy for developers to build web applications and tools that interact with the Archway network. It acts as a drop-in replacement for the CosmJS client library, extending its functionality and allowing for easier interaction with Archway's reward and fee sub-systems.

To delve deeper into the internal mechanics of arch3.js, refer to the API documentation available at https://archway-network.github.io/arch3.js.

Installation

To install arch3.js, you have the option of using either npm or yarn:

NPM

npm install --save @archwayhq/arch3.js

Yarn

yarn add @archwayhq/arch3.js

Query

Below is simple example on querying Nomos multisig to get members of multisig:

import { ArchwayClient } from '@archwayhq/arch3.js';

const client = await ArchwayClient.connect('https://rpc.constantine.archway.tech');
const contractAddress = "abcdefg";
// Get members
const queryMembers = {  get_members: [] };
const { members } = await client.queryContractSmart(  contractAddress,  queryMembers);
console.log("Members: ", members);

Execution

Below is simple example on execute vote transaction to Nomos multisig:

import { SigningArchwayClient } from "@archwayhq/arch3.js";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import "dotenv/config";

const contractAddress = process.env.CONTRACT_ADDR;
const mnemonic = process.env.MNEMONIC;

const network = {
    chainId: "constantine-3",
    endpoint: "https://rpc.constantine.archway.tech",
    prefix: "archway",
};
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: network.prefix, });
const accounts = await wallet.getAccounts();

const tx_client = await SigningArchwayClient.connectWithSigner(
    network.endpoint,
    wallet
);
const txId = "set-this";
const executeMsg = {
    vote_transaction: txId,
    vote: 1,
};

const response = await tx_client.execute(
accounts[0].address,
contractAddress,
executeMsg,
"auto"
);

console.log("Response: ", JSON.stringify(response));
console.log("Transaction Hash: ", response.transactionHash);

Nomos JSON Schema

To find reference on what interactions we can have with the contract, we can see the json schema in contract folder, in that example we can find how the json structure should be for instantiate message, execute message, query, and contract response.

Last updated