Javascript developer library to interact with JMES Network
In order to use this library, you will need to add it to your project as a dependency.
Having NodeJS installed:
npm install jmes
For browser usage, you can also directly rely on unpkg :
<script src="https://unpkg.com/jmes"></script>
We define a Wallet as a primitives that is initiated from a root private key
A Wallet can be derived into multiple Account (that have individual public/private key pair).
import { Client, Mnemonic } from 'jmes.js'
const client = new Client();
const mnemonic = new Mnemonic();
// Initiate a wallet from a specific mnemonic or private key
const wallet = client.createWallet(mnemonic);
// Each wallet allow to generate multiple account, by default, it will be index 0.
const account = wallet.getAccount();
// Get an account's Address on jmesxxxx format.
const address = account.getAddress();
const balance = account.getBalance();
// Send transaction
const txResponse = await account.sendTransaction({
recipientAddress: "jmes1g2vaept3rxjvfzyfmem5am5x74n4qygq58jy9v",
recipientAmount: 172064,
})
While this library will handle secpk1256 generation, upon creating a new Mnemonic, it might causes some issues despite overwritting crypto
module.
If so, you can pass specific bytes to the Mnemonic function.
import 'react-native-get-random-values'
const randomBytes = crypto.getRandomValues(new Uint8Array(32));
const mnemonic = Mnemonic.generateMnemonic(randomBytes);
Passing either a Mnemonic or a private key, it will generate a Wallet object.
const mnemonic = new Mnemonic();
const client = new Client();
const wallet = client.createWallet(mnemonic);
Allow an optional denom parameter (default: ujmes). Pass bujmes to get the voting rights supply.
const supply = await client.getSupply();
Return a specific validator information.
const validatorInfo = await client.getValidatorInfo(validatorAddress);
Return the list of validators.
const validators = await client.getValidators();
Return an Account object from an optional specified index.
const account = wallet.getAccount();
Return the account address on jmesxxxx format. Allow an optional address index parameter (default: 0).
const address = account.getAddress();
Return the account balance. Allow an optional address parameter (default .getAddress()).
const balance = account.getBalance();
Return the account voting rights. Allow an optional address parameter (default .getAddress()).
const votingRights = account.getVotingRights();
Send a transaction from the account.
const txResponse = await account.sendTransaction({
recipientAddress: "jmes1g2vaept3rxjvfzyfmem5am5x74n4qygq58jy9v",
recipientAmount: 172064,
})
Withdraw the validator commission.
const txResponse = await account.withdrawCommission(validatorAddress);
Withdraw the delagation rewards for a set of validator.
const txResponse = await account.withdrawRewards(delegatorAddress, validatorAddresses);
Delegate tokens to a validator. Specified amount is in Coin primitives.
const txResponse = await account.delegateTokens(validatorAddress, amount);
Undelegate tokens from a validator. Specified amount is in Coin primitives.
const txResponse = await account.undelegateTokens(validatorAddress, amount);
A coin primitive is used to represent a specific amount of tokens.
const {Core:{Coin}} = require("jmes.js");
const coin = new Coin(1000000, "ujmes");