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.

const wallet = ethereumWallet.recoverWallet("...12 word phrases...")

Create master seed

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

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

const masterSeed = await ethereumWallet.createMasterSeedFromMnemonic("...12 word phrases...")

Create account

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

Create account from master seed and returns EvmAccount object.

const account = await ethereumWallet.createAccount(masterSeed)

Recover account

ethereumWallet.importAccount(privateKey: string) => EvmAccount

Recover account from private key string and returns EvmAccount object.

const account = await ethereumWallet.importAccount(privateKey)

Get ETH balance

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

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

const balance = await ethereumWallet.getBalance()

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.

const detail = await ethereumWallet.getToken(tokenAddress)

Get token balance

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

Get balance of selected token and returns BigInt value.

const tokenBalance = await ethereumWallet.getTokenBalance(tokenAddress)

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.

const tx = await ethereumWallet.sendEther(recipientAddress, amount)

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.

const tx = await ethereumWallet.tokenApprove(tokenAddress, amount, recipient)

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.

const tx = await ethereumWallet.tokenTransfer(tokenAddress, amount, recipient)

Check contract address

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

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

const isContractAddress = await ethereumWallet.isContractAddress(address)

Check NFT contract address

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

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

const isNFTContract = await ethereumWallet.isNftContract(address)

Check ERC721 contract

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

Returns if given contract address is ERC721 standard or not.

const is721NFT = await ethereumWallet.isERC721NFT(address)

Check ERC1155 contract

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

Returns if given contract address is ERC1155 standard or not.

const is1155NFT = await ethereumWallet.isERC1155NFT(address)

Get contract instance

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

Return Contract object from contract address and ABI interface.

const contract = ethereumWallet.getContract(address, abi)

Convert gwei to wei

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

Convert gwei to wei and returns Big number value.

const weiValue = ethereumWallet.util.gweiToWei(gweiValue)

Convert gwei to eth

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

Convert gwei to ETH and returns string value.

const ethValue = ethereumWallet.util.gweiToEther(gweiValue)

Convert wei to eth

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

Convert wei to ETH and returns string value.

const ethValue = ethereumWallet.util.weiToEther(weiValue)

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.

const latency = await ethereumWallet.util.getJsonRPCLatency(rpcUrl)

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.

const latency = await ethereumWallet.util.getWebSocketRPCLatency(rpcUrl)

Last updated