Skip to main content

Usage

Send your first transaction

import {Secp256k1HdWallet, ShareledgerSigningClient, calculateFee} from "@shareledgerjs/client";

const mnemonic = "your 12 (15, 18, 21 or 24) -words passphrase";
const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic);
const [firstAccount] = await wallet.getAccounts();

const rpcEndpoint = "https://rpc-testnet.shareri.ng";
const client = await ShareledgerClient.connect(endpoint, wallet);

const recipient = "shareledger1mrzlepu0kfz5x0h40fa6d20te0maja7e4c97ts";
const msg = client.bank.send(firstAccount.address, recipient, [{ amount: "10000000000000", denom: "nshr" }]);
const response = await client.signAndBroadcast(firstAccount.address, [msg]);
// fee can be optionally specified
// const gasLimit = 250000;
// const fee = calculateFee(gasLimit, "500nshr");
// const response = await client.signAndBroadcast(firstAccount.address, [msg], fee);
assertIsBroadcastTxSuccess(result);

Query your delegations

import {ShareledgerClient} from "@shareledgerjs/client";

const client = await ShareledgerClient.connect(endpoint);
const response = await client.staking.delegatorDelegations("your delegator address");

Calculate transaction hash

import {ShareledgerClient} from "@shareledgerjs/client";

// you can go with offline mode, no RPC connection
const client = new ShareledgerClient(undefined, {});
// base64 string or Uint8Array
const rawTx = "Cp0BCpoBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnoKMnNoYXJlbGVkZ2VyMW1yemxlcHUwa2Z6NXgwaDQwZmE2ZDIwdGUwbWFqYTdlNGM5N3RzEjJzaGFyZWxlZGdlcjFtcnpsZXB1MGtmejV4MGg0MGZhNmQyMHRlMG1hamE3ZTRjOTd0cxoQCgRuc2hyEggxMDAwMDAwMBJtClEKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECnlVX/lqffc9GKB/w0g78V+q4TUFHLP8IMwnVI9QILZwSBAoCCAEYswESGAoSCgRuc2hyEgozNzcwMDAwMDAwELq/BRpAgioCrmZvDDdVVwiCuiqgDc9nde2qjg3KXHwjcTgQRWBJbuKEDa2E/dh3i82kZgBcgMoRRRtRvf6oQ5AwYCD92Q==";
const txHash = client.getTxHash(rawTx);

Initialize a wallet or generate a new one

import {Secp256k1HdWallet} from "@shareledgerjs/client";

const wallet = await Secp256k1HdWallet.generate();
const [account] = await wallet.getAccounts();

const wallet2 = await Secp256k1HdWallet.fromMnemonic("<your 12(|15|18|21|24)-word passphrase>");
const [account2] = await wallet.getAccounts();

See more at API Reference.