@mantrachain/mantrajs
v1.0.0-beta.2
Published
JS and TS types relating to Protocol Buffers for MANTRA Chain
Downloads
238
Readme
MANTRA Chain Kit - MANTRAJS
Installation
npm install @mantrachain/mantrajs
Usage
Import the package
import { mantrachain } from "@mantrachain/mantrajs/index";
or
const mantrachain = require('@mantrachain/mantrajs');
Query Balances (LCD Client)
const client = await mantrachain.ClientFactory.createAppApiClient({
restEndpoint,
});
const response = await client.cosmos.bank.v1beta1.allBalances({
address: "mantra15m77x4pe6w9vtpuqm22qxu0ds7vn4ehzwx8pls",
resolveDenom: false,
});
Response:
{
balances: [
{
denom: 'factory/mantra15m77x4pe6w9vtpuqm22qxu0ds7vn4ehzwx8pls/MATT2',
amount: '250'
},
{ denom: 'uom', amount: '78883121160383' }
],
pagination: { next_key: null, total: '2' }
}
Query Balance (RPC Client)
const client = await mantrachain.ClientFactory.createAppRPCQueryClient({
rpcEndpoint,
});
const response = await client.cosmos.bank.v1beta1.allBalances({
address: "mantra15m77x4pe6w9vtpuqm22qxu0ds7vn4ehzwx8pls",
resolveDenom: false,
});
Response:
{
balances: [
{
denom: 'factory/mantra15m77x4pe6w9vtpuqm22qxu0ds7vn4ehzwx8pls/MATT2',
amount: '250'
},
{ denom: 'uom', amount: '78883121160383' }
],
pagination: { nextKey: Uint8Array(0) [], total: 2n }
}
Signing Transactions
Use the MessageComposer in the required namespace to create the message and the SigningMantrachainClient
to sign and broadcast. For example to using the Cosmos SDK Bank Send:
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonicSender, {
prefix: "mantra",
});
const accounts = await wallet.getAccounts();
const address = accounts[0].address;
const signingClient = await getSigningMantrachainClient({
rpcEndpoint,
signer: wallet,
});
const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;
const sendMsg = send({
fromAddress: address,
toAddress: "mantra12z5kd26nlggsrmt3dx3v3eyxy7pmgdz5h7qf4t",
amount: [{ denom: "uom", amount: "1000" }],
});
const fee = { amount: [{ denom: "uom", amount: "5000" }], gas: "200000" };
const response = await signingClient.signAndBroadcast(
address,
[sendMsg],
fee,
"Test transfer"
);
Contributors
First Build?
This repo uses submodules that need to be synced. The first time you clone this repo and build follow the following steps:
- Run
git submodule update --init --recursive --remote
- Run
cd packages/mantrajs && ./scripts/set-versions.sh
- Run
npm install
- Run
npm run rebuild
Tests
Test are run against the DuKong Test Network and only test a limited number of items. For more comprehensive tests use the E2E test repo.
To run the tests:
npm test
Submodules
The proto files are referenced from the submodules. You can modify and use ./scripts/set-versions.sh
to set the versions/commits you wish to use for each submodule.
If it's the first time you check-out a repo you need to use --init
first:
git submodule update --recursive --remote
otherwise use:
git submodule update --recursive
or
git pull --recurse-submodules
Adding a new Cosmos SDK Module
- To add a new submodule use:
git submodule add -f [email protected]:skip-mev/feemarket.git packages/mantrajs/protos/feemarket-src
then checkout the version/commit you want use the script or manually run it
git -C protos/feemarket-src checkout v1.1.1
NOTE: you should update
./scripts/set-versions.sh
and run it
then in
package.json
add the newprotogen:newxxx
task and update theclean
tasknext update
./scripts/codegen.js
git submodule add -f [email protected]:MANTRA-Chain/mantrachain.git packages/mantrajs/protos/mantrachain-src git submodule add -f [email protected]:MANTRA-Chain/cosmos-sdk.git packages/mantrajs/protos/cosmos-sdk-src git submodule add -f [email protected]:skip-mev/connect.git packages/mantrajs/protos/connect-src git submodule add -f [email protected]:cosmos/ibc-go.git packages/mantrajs/protos/ibc-go-src