Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/abi

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/abi

Utilities and Classes for parsing, formatting and managing Ethereum ABIs.

  • 5.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
993K
increased by2.8%
Maintainers
1
Weekly downloads
 
Created

What is @ethersproject/abi?

@ethersproject/abi is a part of the ethers.js library, which is a complete and compact library for interacting with the Ethereum blockchain and its ecosystem. The @ethersproject/abi package specifically deals with encoding and decoding data according to the Ethereum ABI (Application Binary Interface) specifications. This is essential for interacting with smart contracts, as it allows you to encode function calls and decode the data returned by smart contracts.

What are @ethersproject/abi's main functionalities?

Encoding Function Calls

This feature allows you to encode function calls to be sent to the Ethereum blockchain. In this example, the `transfer` function is encoded with the specified parameters.

const { Interface } = require('@ethersproject/abi');
const abi = [
  "function transfer(address to, uint amount)"
];
const iface = new Interface(abi);
const data = iface.encodeFunctionData("transfer", ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", 1000]);
console.log(data);

Decoding Function Results

This feature allows you to decode the results returned by a smart contract function call. In this example, the result of the `balanceOf` function is decoded.

const { Interface } = require('@ethersproject/abi');
const abi = [
  "function balanceOf(address owner) view returns (uint)"
];
const iface = new Interface(abi);
const result = iface.decodeFunctionResult("balanceOf", "0x00000000000000000000000000000000000000000000000000000000000003e8");
console.log(result);

Parsing Event Logs

This feature allows you to parse event logs emitted by smart contracts. In this example, a `Transfer` event log is parsed to extract the event details.

const { Interface } = require('@ethersproject/abi');
const abi = [
  "event Transfer(address indexed from, address indexed to, uint amount)"
];
const iface = new Interface(abi);
const log = {
  data: "0x00000000000000000000000000000000000000000000000000000000000003e8",
  topics: [
    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
    "0x000000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e",
    "0x000000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e"
  ]
};
const event = iface.parseLog(log);
console.log(event);

Other packages similar to @ethersproject/abi

Keywords

FAQs

Package last updated on 10 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc