Socket
Socket
Sign inDemoInstall

@ethersproject/abi

Package Overview
Dependencies
9
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/abi

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


Version published
Weekly downloads
728K
decreased by-12.27%
Maintainers
1
Created
Weekly downloads
 

Package description

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

Readme

Source

Ethereum ABI Coder

This sub-module is part of the ethers project.

It is responsible for encoding and decoding the Application Binary Interface (ABI) used by most smart contracts to interoperate between other smart contracts and clients.

For more information, see the documentation.

Importing

Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.

const {

    ConstructorFragment,
    EventFragment,
    Fragment,
    FunctionFragment,
    ParamType,
    FormatTypes,

    AbiCoder,
    defaultAbiCoder,

    Interface,
    Indexed,

    /////////////////////////
    // Types

    CoerceFunc,
    JsonFragment,
    JsonFragmentType,

    Result,
    checkResultErrors,

    LogDescription,
    TransactionDescription

} = require("@ethersproject/abi");

License

MIT License

Keywords

FAQs

Last updated on 19 Aug 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc