Skip to content

Metamask: Getting transaction history via Ethers.js

Displaying surkry in Metamke use Ethers.js

As a creator Building, Ethereum Blockchain, you are probly familiar With the poplar clier. However, showing the history of surgry can be a challenge. In this article, we will investigate how to get and display the resulting operations.js, JavaScript Library for interacts.

What do you need surkry hisstory?

Showing the history of transactions is very important for variety of cases souch as:

* Wallets: To monitor the incoming and outgoing operations.

* Market Analysis Tools:

Visualize Purchase and Sales Over time.

* Security Audits: To ensure, that your wallets do of illegities.

** Step

To show you the resulting operations in your Metamk wallet uses Ethers.

  • Install Ethers.js : Launch NPM Install Ethers.js or Yarn Add Ethers.js in your program.

  • Import the library and set the provider : Create a copy of the Etherum provider Using Ethers.Provders.jsonrpcpovider. For example:

`Javascript

Const provider = new ethers.providers.jsonrpcrovider (‘

`

Change your_Prreat_id on your act infura program ID.

  • Get your wallet dddress : import a Metamask cash copy Using Ethers.Wallet.fromprivatekey. You lock to upload a private key a lock or local cash storage:

`Javascript

CONST WALLET = Wait for Ethers.Wallet.fromkey (Privatekey);

`

Change Privatekey With your actual Ethereum private key.

  • Get Operations Operations

    Metamask: Getting transaction history via Ethers.js

    : Use a provider copy to rechet a list of transactions to the that the specfied address.Providers.Providers.Providers.Providers. API:

`Javascript

Async’s feature ofequedransations () {

Const Web3 = New Ethers.Providers.jsonrpcprovider (‘

CONST WALLETADDRESS = ‘0x … Yourwalletaddress …’;

triy {

CONST GEDTRANSACTIONS = Waiting for Web3.eth.GetTransactionHistory (Walletaddress, {{{{{{{{{{{ .

Calculation: 100,

Since Block: “the latest”,

Site: ‘Latest’,

});

Return gautransations.map ((surgury) => operation.transaction);

} catch (error) {

console.error (error);

return [];

}

}

`

This code scans the list of the specified cash eddress operations. You can that analyze and show thees.

  • Show Operations : Ohn yu the resulting operations, you can use Ethers.js to crate using Ethers.Providers.web3P3P3PROVIDER.

For example:

`Javascript

Async’s feature Displayedtransations () {)

Const Web3 = New Ethers.Providers.jsonrpcprovider (‘

CESS Gautransations = Waiting for Betrecevedransations ();

console.log (broadcast);

}

`

CODE EXAMPLE

Here’s a comprehensive example you can copy and paste it in your program:

`Javascript

Imported * as ether from “ether”;

import {web3provider} prior ‘@Web3 provider’;

// Set the copy of the Ethereum provider

CONST provider = new web3provider (‘

// Get’

CONST PRIVATEKEY = ‘0x … YourWALLETPRIVATEKEY …’);

CONST WALLETADDRESS = ‘0x … Yourwalletaddress …’;

Async’s feature ofequedransatsions () {

triy {

Const Gauttransatsion = Waiting for Provider.eth.gettransactionhistory (Walletaddress, {{ {{

Calculation: 100,

Since Block: “the latest”,

Site: ‘Latest’,

});

Return gautransations.map ((surgury) => operation.transaction);

} catch (error) {

console.

BITCOIN THERE GROUP