var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=1&rec=1&url=https://docs.terra.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Wallets

Create a wallet

Use LCDClient.wallet() to create a Wallet from a Key.

import { LCDClient, MnemonicKey } from '@terra-money/feather.js';

const terra = new LCDClient(...);

const mk = new MnemonicKey();
const wallet = terra.wallet(mk);
Copy

In the above example, a MnemonicKey was specified for the wallet, but any type of Key implementation can be used instead.

Usage

Getting account number and sequence

A wallet is connected to the Terra blockchain and can poll the values of an account's account number and sequence directly:

console.log(await wallet.accountNumber());
console.log(await wallet.sequence());
Copy

Creating transactions

A wallet makes it easy to create a transaction by automatically fetching the account number and sequence from the blockchain. The fee parameter is optional -- if you don't include it, feather.js will automatically use your LCD's fee estimation settings to simulate the transaction within the node and include the resultant fee in your transaction.

const msgs = [ ... ]; // list of messages
const fee = Fee(...); // optional fee

const unsignedTx = await wallet.createTx({
msgs,
chainID: 'pisco-1',
// fee, (optional)
memo: 'this is optional'
});
Copy

You can then sign the transaction with the wallet's key, which will create a StdTx which you can later broadcast:

const tx = wallet.key.signTx(unsignedTx);
Copy

You can also use the more convenient Wallet.createAndSignTx() function, which automatically generates a signed transaction to be broadcast:

const tx = await wallet.createAndSignTx({
msgs,
fee,
chainID: 'pisco-1',
memo: 'this is optional',
});
Copy