# Ethereum

### Import Ethereum Wallet

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

### Reference

#### Create wallet SDK instance

#### *class* **EthereumWallet***(<mark style="color:purple;">rpcUrl</mark>: <mark style="color:blue;">string</mark>, <mark style="color:purple;">privateKey</mark>?: <mark style="color:blue;">string</mark>)*

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

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

#### Create new wallet

#### *ethereumWallet*.createWalle&#x74;*(<mark style="color:purple;">nonce</mark>?: <mark style="color:blue;">string</mark>) => <mark style="color:blue;">EvmWallet</mark>*

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

```javascript
const wallet = ethereumWallet.createWallet()
```

#### Recover wallet

#### *ethereumWallet*.recoverWalle&#x74;*(<mark style="color:purple;">mnemonic</mark>: <mark style="color:blue;">string</mark>, <mark style="color:purple;">nonce</mark>?: <mark style="color:blue;">number</mark>) => <mark style="color:blue;">EvmWallet</mark>*

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

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

#### Create master seed

#### *ethereumWallet*.createMasterSeedFromMnemoni&#x63;*(<mark style="color:purple;">mnemonic</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">Buffer</mark>>*

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

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

#### Create account

#### *ethereumWallet*.createAccoun&#x74;*(<mark style="color:purple;">rootSeed</mark>: <mark style="color:blue;">Buffer</mark>,* *<mark style="color:purple;">nonce</mark>?: <mark style="color:blue;">numer</mark>) => Promise<<mark style="color:blue;">EvmAccount</mark>>*

Create account from master seed and returns EvmAccount object.

```typescript
const account = await ethereumWallet.createAccount(masterSeed)
```

#### Recover account&#x20;

#### *ethereumWallet*.importAccoun&#x74;*(<mark style="color:purple;">privateKey</mark>: <mark style="color:blue;">string</mark>) => <mark style="color:blue;">EvmAccount</mark>*

Recover account from private key string and returns EvmAccount object.

```typescript
const account = await ethereumWallet.importAccount(privateKey)
```

#### Get ETH balance

#### *ethereumWallet*.getBalanc&#x65;*(<mark style="color:purple;">address</mark>?: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">BigNumberish</mark>>*

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

```typescript
const balance = await ethereumWallet.getBalance()
```

#### Get token detail

#### *ethereumWallet*.getToke&#x6E;*(<mark style="color:purple;">tokenAddress</mark>: <mark style="color:blue;">string,</mark> <mark style="color:purple;">address?:</mark> <mark style="color:blue;">string</mark>,* *<mark style="color:purple;">tokenId</mark>?: <mark style="color:blue;">number</mark>) => Promise<<mark style="color:blue;">EvmTokenDetail</mark>>*

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

```typescript
const detail = await ethereumWallet.getToken(tokenAddress)
```

#### Get  token balance

#### *ethereumWallet*.getTokenBalanc&#x65;*(<mark style="color:purple;">tokenAddress</mark>: <mark style="color:blue;">string,</mark> <mark style="color:purple;">address?:</mark> <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">BigInt</mark>>*

Get balance of selected token and returns BigInt value.

```typescript
const tokenBalance = await ethereumWallet.getTokenBalance(tokenAddress)
```

#### Send payment transaction

#### *ethereumWallet*.sendEthe&#x72;*(<mark style="color:purple;">recipient</mark>: <mark style="color:blue;">string,</mark> <mark style="color:purple;">amount:</mark> <mark style="color:blue;">string,</mark> <mark style="color:purple;">gasPrice</mark>?: <mark style="color:blue;">any,</mark> <mark style="color:purple;">gasLimite</mark>?: <mark style="color:blue;">any</mark>) => Promise<<mark style="color:blue;">TransactionResponse</mark>>*

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

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

#### Approve token

#### *ethereumWallet*.tokenApprov&#x65;*(<mark style="color:purple;">tokenAddress</mark>: <mark style="color:blue;">string,</mark> <mark style="color:purple;">amount:</mark> <mark style="color:blue;">string,</mark> <mark style="color:purple;">recipient</mark><mark style="color:blue;">: string,</mark> <mark style="color:purple;">gasPrice</mark>?: <mark style="color:blue;">any,</mark> <mark style="color:purple;">gasLimite</mark>?: <mark style="color:blue;">any</mark>) => Promise<<mark style="color:blue;">TransactionResponse</mark>>*

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

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

#### Transfer token

#### *ethereumWallet*.tokenTransfe&#x72;*(<mark style="color:purple;">tokenAddress</mark>: <mark style="color:blue;">string,</mark> <mark style="color:purple;">amount:</mark> <mark style="color:blue;">any,</mark> <mark style="color:purple;">recipient</mark><mark style="color:blue;">: string,</mark> <mark style="color:purple;">gasPrice</mark>?: <mark style="color:blue;">any,</mark> <mark style="color:purple;">gasLimite</mark>?: <mark style="color:blue;">any</mark>) => Promise<<mark style="color:blue;">TransactionResponse</mark>>*

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

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

#### Check contract address

#### *ethereumWallet*.isContractAddres&#x73;*(<mark style="color:purple;">address</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">boolean</mark>>*

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

```typescript
const isContractAddress = await ethereumWallet.isContractAddress(address)
```

#### Check NFT contract address

#### *ethereumWallet*.isNftContra&#x74;*(<mark style="color:purple;">address</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">IsNFT</mark>>*

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

```typescript
const isNFTContract = await ethereumWallet.isNftContract(address)
```

#### Check ERC721 contract

#### *ethereumWallet*.isERC721NF&#x54;*(<mark style="color:purple;">address</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">boolean</mark>>*

Returns if given contract address is ERC721 standard or not.

```typescript
const is721NFT = await ethereumWallet.isERC721NFT(address)
```

#### Check ERC1155 contract

#### *ethereumWallet*.isERC1155NF&#x54;*(<mark style="color:purple;">address</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">boolean</mark>>*

Returns if given contract address is ERC1155 standard or not.

```typescript
const is1155NFT = await ethereumWallet.isERC1155NFT(address)
```

#### Get contract instance

#### *ethereumWallet*.getContrac&#x74;*(<mark style="color:purple;">address</mark>: <mark style="color:blue;">string</mark>,* *<mark style="color:purple;">abi</mark>: <mark style="color:blue;">InterfaceAbi</mark>) => <mark style="color:blue;">Contract</mark>*

Return Contract object from contract address and ABI interface.

```typescript
const contract = ethereumWallet.getContract(address, abi)
```

#### Convert gwei to wei

#### *ethereumWallet*.util.gweiToWe&#x69;*(<mark style="color:purple;">amount</mark>: <mark style="color:blue;">string</mark> | <mark style="color:blue;">number</mark>) => <mark style="color:blue;">BigNumberish</mark>*

Convert gwei to wei and returns Big number value.

```typescript
const weiValue = ethereumWallet.util.gweiToWei(gweiValue)
```

#### Convert gwei to eth

#### *ethereumWallet*.util.gweiToEthe&#x72;*(<mark style="color:purple;">amount</mark>: <mark style="color:blue;">string</mark> | <mark style="color:blue;">number</mark>) => <mark style="color:blue;">string</mark>*

Convert gwei to ETH and returns string value.

```typescript
const ethValue = ethereumWallet.util.gweiToEther(gweiValue)
```

#### Convert wei to eth

#### *ethereumWallet*.util.weiToEthe&#x72;*(<mark style="color:purple;">amount</mark>: <mark style="color:blue;">string</mark> | <mark style="color:blue;">number</mark>) => <mark style="color:blue;">string</mark>*

Convert wei to ETH and returns string value.

```typescript
const ethValue = ethereumWallet.util.weiToEther(weiValue)
```

#### Get JSON RPC server latency

#### *ethereumWallet*.util.getJsonRPCLatenc&#x79;*(<mark style="color:purple;">rpcUrl</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">number</mark>>*

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

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

#### Get WebSocket RPC server latency

#### *ethereumWallet*.util.getWebSocketRPCLatenc&#x79;*(<mark style="color:purple;">rpcUrl</mark>: <mark style="color:blue;">string</mark>) => Promise<<mark style="color:blue;">number</mark>>*

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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cybers-organization-5.gitbook.io/multichain-wallet-sdk-documentation/reference/sdk-reference/ethereum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
