Wallets
Create a wallet
Use LCDClient.wallet()
to create a Wallet
from a Key
.
_6import { LCDClient, MnemonicKey } from '@terra-money/feather.js';_6_6const terra = new LCDClient(...);_6_6const mk = new MnemonicKey();_6const wallet = terra.wallet(mk);
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:
_2console.log(await wallet.accountNumber());_2console.log(await wallet.sequence());
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.
_9const msgs = [ ... ]; // list of messages_9const fee = Fee(...); // optional fee_9_9const unsignedTx = await wallet.createTx({_9 msgs,_9 chainID: 'pisco-1',_9 // fee, (optional)_9 memo: 'this is optional'_9});
You can then sign the transaction with the wallet's key, which will create a StdTx
which you can later broadcast:
_1const tx = wallet.key.signTx(unsignedTx);
You can also use the more convenient Wallet.createAndSignTx()
function, which automatically generates a signed transaction to be broadcast:
_6const tx = await wallet.createAndSignTx({_6 msgs,_6 fee,_6 chainID: 'pisco-1',_6 memo: 'this is optional',_6});