Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@archwayhq/arch3-core

archway-network3.9kApache-2.00.7.5TypeScript support: included

Core library to interact with Archway Network

archway, cosmos, cosmjs, cosmosjs, cosmwasm, tendermint, atom, wasm, smart-contracts, blockchain, dapp, dapps, nft, tooling, web3

readme

arch3.js

npm (scoped) Tests CodeQL Codacy Badge Codacy Badge License

arch3.js is an all-in-one library to interact with the Archway Protocol. It extends CosmJS CosmWasm Stargate clients' functionalities to connect with Archway's reward system. It automatically calculates the network's minimum consensus fee and contract premiums before broadcasting transactions to the chain.

This package is not a replacement for CosmJS and is intended to work in conjunction with the other modules available in @cosmjs/*.

Installation

NPM

npm install --save @archwayhq/arch3.js

Yarn

yarn add @archwayhq/arch3.js

Documentation

For a complete reference on the classes and methods available, please check the API docs.

Compatibility table

List of Archway protocol versions compatible with arch3.js:

archwayd arch3.js
>=6.0.0 >=0.6.0
5.0.0 0.5.0
0.5.0 to 4.0.2 0.2.0 to 0.4.0
<0.5.0 0.1.0

To query the current archwayd version running on a node, you can execute:

curl -sfL 'https://rpc.constantine.archway.tech/abci_info' | jq -r '.result.response.version'

Sample Usage

The examples suppose you deployed the increment contract template to Constantine.

You can also take a look on the test specs for more examples on how to use each of the methods available in the clients.

Query

For quering the chain, use the ArchwayClient:

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

const endpoint = 'https://rpc.constantine-3.archway.tech';
const client = await ArchwayClient.connect(endpoint);

Querying a contract

const contractAddress = 'archway14v952t75xgnufzlrft52ekltt8nsu9gxqh4xz55qfm6wqslc0spqspc5lm';
const msg = {
  get_count: {},
};
const { count } = await client.queryContractSmart(contractAddress, msg);

Querying outstanding rewards

const rewardsAddress = 'archway14v952t75xgnufzlrft52ekltt8nsu9gxqh4xz55qfm6wqslc0spqspc5lm';
const { totalRewards, totalRecords } = await client.getOutstandingRewards(aliceAddress);

Execute transactions

For signing and broadcasting transactions, create a SigningArchwayClient using a signing wallet:

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

const network = {
  endpoint: 'https://rpc.constantine-3.archway.tech',
  prefix: 'archway',
};

const walletMnemonic = 'culture blossom ten thing bar ...';

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(walletMnemonic, { prefix: network.prefix });
const client = await SigningArchwayClient.connectWithSigner(network.endpoint, wallet);

Executing an action in a smart contract

const accounts = await wallet.getAccounts();
const contractAddress = 'archway14v952t75xgnufzlrft52ekltt8nsu9gxqh4xz55qfm6wqslc0spqspc5lm';
const msg = {
  increment: {},
};

const { transactionHash } = await client.execute(accounts[0].address, contractAddress, msg, 'auto');

Setting a contract metadata

const accounts = await wallet.getAccounts();
const metadata = {
  contractAddress: 'archway14v952t75xgnufzlrft52ekltt8nsu9gxqh4xz55qfm6wqslc0spqspc5lm',
  ownerAddress: accounts[0].address,
  rewardsAddress: accounts[0].address,
};

const { transactionHash } = await client.setContractMetadata(accounts[0].address, metadata, 'auto');

Withdrawing rewards

const accounts = await wallet.getAccounts();
const contractAddress = 'archway14v952t75xgnufzlrft52ekltt8nsu9gxqh4xz55qfm6wqslc0spqspc5lm';

// The address withdrawing the rewards should be the same
// as the `rewardsAddress` set in the contract metadata
const {
  transactionHash,
  rewards
} = await client.withdrawContractRewards(accounts[0].address, contractAddress, msg, 'auto');

Development

See HACKING.md.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v0.7.5 (2024-12-12)

Fixed

arch3-core

  • Fixed Authz Amino converter support for /cosmos.authz.v1beta1.MsgGrant with inner /cosmos.bank.v1beta1.SendAuthorization authorization, without an allowList. ([#124])

v0.7.4 (2024-12-11)

Added

arch3-core

  • new createAuthzAminoConverters that allows Amino/Ledger support for /cosmos.authz.v1beta1.MsgGrant with inner /cosmos.authz.v1beta1.GenericAuthorization or /cosmos.bank.v1beta1.SendAuthorization authorization, and also support for /cosmos.authz.v1beta1.MsgRevoke ([#123])

v0.7.3 (2024-09-12)

Fixed

arch3-core

  • refactor connectToRpcClient into connectCometWithBatchClient, adding back support for using Comet38Client with 0.38.x RPC Clients ([#123])

v0.7.2 (2024-09-11)

Fixed

arch3-core

  • make connectToRpcClient use 0.37.x version of Tendermint for both 0.37.x and 0.38.x RPC Clients as a workaround for a bug in batching requests in Archway V9 ([#121])

v0.7.1 (2024-07-08)

Added

arch3-core

  • add granter and payer arguments to the SigningArchwayClient's simulate method ([#119])
  • add simulateTx method to the ArchwayClient and SigningArchwayClient classes ([#119])

Changed

arch3-core

  • use granter and payer args in the simulate call inside the SigningArchwayClient's calculateFee method ([#119])

v0.7.0 (2024-02-28)

BREAKING CHANGES

  • change the type of gasWanted and gasUsedof TxResult from number to bigint, to match the new types returned by @cosmjs/cosmwasm-stargate (#115)

Changed

  • removed long package (#115)

arch3-core

  • replace deprecated TendermintClient with CometClient (#115)
  • autodetect Tendermint/CometBFT version needed on ArchwayClient.connectWithBatchClientand SigningArchwayClient.connectWithSignerAndBatchClient (#115)

arch3-proto

  • update @cosmology/telescope to version 1.4.12, and update codegen config with the option useTelescopeGeneratedType = true as a workaround for currently open issue #482 of @cosmology/telescope (#115)
  • update codegen script and compile proto files (#115)

v0.6.0 (2024-02-06)

BREAKING CHANGES

  • the new version of arch3.js will, by default, be compatible only with the Archway protocol version 6.0.0 and above.

Added

arch3-core

  • added withdrawToWallet property to the ContractMetadata interface (#114)

Changed

arch3-proto

  • updated to the version 6.0.0 of the protocol (#114)

v0.5.0 (2023-11-21)

BREAKING CHANGES

  • the new version of arch3.js will, by default, be compatible only with the Archway protocol version 5.0.0 and above.

Added

arch3-core

  • added add getAllBalances method to the ArchwayClient (#110)

Changed

  • upgraded project to Typescript 5.2.2 (#104)

arch3-core

  • changed the default Tendermint client to 0.37 (#106)
  • increased the default gas adjustment to 1.5 (#106)

arch3-proto

  • switched to @cosmology/telescope package to compile proto files (#104)
  • updated to the version 5.0.1 of the protocol (#106)

v0.4.0 (2023-06-27)

Added

arch3-core

  • added support to create an SigningArchwayClient using an HttpBatchClient (#97)
  • added support to create an ArchwayClient using an HttpBatchClient (#96)

Changed

arch3-core

  • bump @cosmjs/* to 0.31.0 (#95)

Fixed

arch3-core

  • gracefully handle withdrawing reward contracts when no rewards exist (#91)

v0.3.1 (2023-06-02)

Added

arch3-core

  • use the type SigningArchwayClientOptions for the options in all factory methods of the SigningArchwayClient (#89)

v0.3.0 (2023-05-30)

BREAKING CHANGES

  • modified the response of ArchwayCLient.getEstimateTxFees to change the estimatedFee type from Coin[] to StdFee and moved the gasLimit into estimatedFee.gas

Added

arch3-core

  • method to calculateFees for multiple messages on SigningArchwayClient (#86)

Changes

arch3-core

  • deprecated the default gasPrice option on SigningArchwayClient (#86)

v0.2.0 (2023-05-17)

BREAKING CHANGES

  • the package @cosmjs/cosmwasm-stargate is not re-exported with @archwayhq/arch-core anymore

Added

arch3-core

  • automatically estimate fees before signing (#68)
  • add x/rewards transactions to SigningArchwayClient (#67)
  • add x/rewards queries to ArchwayClient (#58)

arch3-proto

  • generate amino types (#62)
  • add protobuf deps (#39)
  • generate protobuf clients using telescope (#37)

Fixed

  • release process (#33)

v0.1.0 (2022-09-23)

Added

arch3-core

  • added the ArchwayClient (#18)
  • added the SigningArchwayClient (#22)
  • added the SigningArchwayClient (#22)