A Wallet
is a user-facing API that is used to interact with an account. A Wallet
instance is tied to a single key
pair and essentially wraps the given Provider
for that specific account.
A wallet can be generated from a randomly generated seed, a private key, or instantiated using a Ledger device.
Using the Wallet
, users can easily interact with the Tendermint2 chain using their account without having to worry
about account management.
Generates a private key-based wallet, using a random seed
options?
AccountWalletOption the account options
Returns Promise
const wallet: Wallet = await Wallet.createRandom();
// random wallet created
Generates a bip39 mnemonic-based wallet
mnemonic
string the bip39 mnemonicoptions?
CreateWalletOptions the wallet generation options
Returns Promise
const mnemonic: string = // ...
const wallet: Wallet = await Wallet.fromMnemonic(mnemonic);
// wallet created from mnemonic
Generates a private key-based wallet
privateKey
string the private keyoptions?
AccountWalletOption the wallet generation options
Returns Promise
// Generate the private key from somewhere
const {publicKey, privateKey} = await generateKeyPair(
entropyToMnemonic(generateEntropy()),
index ? index : 0
);
const wallet: Wallet = await Wallet.fromPrivateKey(privateKey);
// wallet created from private key
Creates a Ledger-based wallet
connector
LedgerConnector the Ledger device connectoroptions?
CreateWalletOptions the wallet generation options
Returns Wallet
const connector: LedgerConnector = // ...
const wallet: Wallet = await Wallet.fromLedger(connector);
// wallet created from Ledger device connection
Connects the wallet to the specified Provider
provider
Provider the active Provider, if any
const provider: Provider = // ...
wallet.connect(provider);
// Provider connected to Wallet
Returns the connected provider, if any
Returns Provider
wallet.getProvider();
// connected provider, if any (undefined if not)
Fetches the address associated with the wallet
Returns Promise
await wallet.getAddress();
// "g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq"
Fetches the account sequence for the wallet
height
number the block height (optional, defaultlatest
)
await wallet.getSequence();
// 42
Returns Promise
Fetches the account number for the wallet. Errors out if the account is not initialized
height
number the block height (optional, defaultlatest
)
Returns Promise
await wallet.getAccountNumber();
// 10
Fetches the account balance for the specific denomination
denomination
string the fund denomination (optional, defaultugnot
)
Returns Promise
await wallet.getBalance('ugnot');
// 5000
Fetches the current (recommended) average gas price
Returns Promise
await wallet.getGasPrice();
// 63000
Estimates the gas limit for the transaction
tx
Tx the transaction that needs estimating
Returns Promise
const tx: Tx = // ...
await wallet.estimateGas(tx);
// 120000
Generates a transaction signature, and appends it to the transaction
tx
Tx the transaction to be signed
Returns Promise<Tx>
const tx: Tx = // ...
await wallet.signTransaction(tx);
// transaction with appended signature
Signs and sends the transaction. Returns the transaction hash (base-64)
tx
Tx the unsigned transaction
Returns Promise
await wallet.sendTransaction(tx);
// returns the transaction hash
Returns the associated signer
Returns Signer
wallet.getSigner(tx);
// Signer instance