Ethereum

This page guides to create and use Ethereum Wallet instance in multichain-wallet-sdk.

Import Ethereum Wallet

import { EthereumWallet } from  'multichain-wallet-sdk';

Reference

Create wallet SDK instance

class EthereumWallet(rpcUrl: string, privateKey?: string)

Without passing privateKey argument, SDK will create wallet that has random private key.

const ethereumWallet = new EthereumWallet("https://eth-mainnet.public.blastapi.io")

Create new wallet

ethereumWallet.createWallet(nonce?: string) => EvmWallet

Create random wallet (address, privateKey, mnemonic, nonce) and returns it as EvmWallet object. Without passing nonce argument, wallet nonoce will be 0 ast default.

const wallet = ethereumWallet.createWallet()

Recover wallet

ethereumWallet.recoverWallet(mnemonic: string, nonce?: number) => EvmWallet

Recover wallet from mnemonic and nonce arguments and returns it as EvmWallet object. Without passing nonce argument, wallet nonoce will be 0 ast default.

Create master seed

ethereumWallet.createMasterSeedFromMnemonic(mnemonic: string) => Promise<Buffer>

Create master seed from mnemonic string and returns it as Buffer.

Create account

ethereumWallet.createAccount(rootSeed: Buffer, nonce?: numer) => Promise<EvmAccount>

Create account from master seed and returns EvmAccount object.

Recover account

ethereumWallet.importAccount(privateKey: string) => EvmAccount

Recover account from private key string and returns EvmAccount object.

Get ETH balance

ethereumWallet.getBalance(address?: string) => Promise<BigNumberish>

Get native coin balance of current wallet or given address and returns BigNumberish object.

Get token detail

ethereumWallet.getToken(tokenAddress: string, address?: string, tokenId?: number) => Promise<EvmTokenDetail>

Get detail info of ERC20 token or NFT and returns EvmTokenDetail object.

Get token balance

ethereumWallet.getTokenBalance(tokenAddress: string, address?: string) => Promise<BigInt>

Get balance of selected token and returns BigInt value.

Send payment transaction

ethereumWallet.sendEther(recipient: string, amount: string, gasPrice?: any, gasLimite?: any) => Promise<TransactionResponse>

Send native currency by create, sign, and broadcast payment transaction and returns executed transaction response object.

Approve token

ethereumWallet.tokenApprove(tokenAddress: string, amount: string, recipient: string, gasPrice?: any, gasLimite?: any) => Promise<TransactionResponse>

Approve given amount of ERC20 token to recipient and returns executed transaction response object.

Transfer token

ethereumWallet.tokenTransfer(tokenAddress: string, amount: any, recipient: string, gasPrice?: any, gasLimite?: any) => Promise<TransactionResponse>

Transfer given amount of ERC20 token to recipient and returns executed transaction response object.

Check contract address

ethereumWallet.isContractAddress(address: string) => Promise<boolean>

Returns boolean value if given address is contract address or external owned account.

Check NFT contract address

ethereumWallet.isNftContrat(address: string) => Promise<IsNFT>

Returns if given contract address is NFT or not and its token type.

Check ERC721 contract

ethereumWallet.isERC721NFT(address: string) => Promise<boolean>

Returns if given contract address is ERC721 standard or not.

Check ERC1155 contract

ethereumWallet.isERC1155NFT(address: string) => Promise<boolean>

Returns if given contract address is ERC1155 standard or not.

Get contract instance

ethereumWallet.getContract(address: string, abi: InterfaceAbi) => Contract

Return Contract object from contract address and ABI interface.

Convert gwei to wei

ethereumWallet.util.gweiToWei(amount: string | number) => BigNumberish

Convert gwei to wei and returns Big number value.

Convert gwei to eth

ethereumWallet.util.gweiToEther(amount: string | number) => string

Convert gwei to ETH and returns string value.

Convert wei to eth

ethereumWallet.util.weiToEther(amount: string | number) => string

Convert wei to ETH and returns string value.

Get JSON RPC server latency

ethereumWallet.util.getJsonRPCLatency(rpcUrl: string) => Promise<number>

Get latency time of JSON RPC server and returns it as seconds value.

Get WebSocket RPC server latency

ethereumWallet.util.getWebSocketRPCLatency(rpcUrl: string) => Promise<number>

Get latency time of WebSOcket RPC server and returns it as secondsd value.

Last updated