Skip to main content

Wallets

Create a wallet

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


_9
import { LCDClient, MnemonicKey } from "@terra-money/terra.js";
_9
_9
const terra = new LCDClient({
_9
URL: "https://phoenix-lcd.terra.dev",
_9
chainId: "phoenix-1",
_9
});
_9
_9
const mk = new MnemonicKey();
_9
const 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 Fluid blockchain and can poll the values of an account's account number and sequence directly:


_2
console.log(await wallet.accountNumber());
_2
console.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, Fluid.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.


_8
const msgs = [ ... ]; // list of messages
_8
const fee = Fee(...); // optional fee
_8
_8
const unsignedTx = await wallet.createTx({
_8
msgs,
_8
// fee, (optional)
_8
memo: 'this is optional'
_8
});

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


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

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


_5
const tx = await wallet.createAndSignTx({
_5
msgs,
_5
fee,
_5
memo: "this is optional",
_5
});