npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

evm-input-data-decoder

v1.0.5

Published

Takes in the input of an EVM transaction, re-orders it into an object with a methodID and an array with each index of up to 64 characters. Then it can console log and return that object. Finally, it can search the object for a unique contract address usin

Downloads

195

Readme

Evm-Input-Data-Decoder

This npm package helps decode Ethereum transaction input data you get when making a call to etherscan or another evm scanner api with a similar URL to this: wallet address transactions. If you look closely at the data, you will see that the transactions that interact with contract addresses have an encoded input field. This package helps decode that input field and extract the method id and parameters. It also identifies and extracts the token contract address from well-known function signatures. The library uses Web3.js under the hood, allowing users to interpret the ABI-encoded data to make sense of contract interactions.

Features

  • Decode Input: Extracts method id and parameters from input string from an EVM transaction.
  • Console log Decode Input: console logs extracted method id and parameters.
  • Get Contract Address: Identifies and extracts the token contract address from a variety of well-known function signatures including (
    • swapETHForExactTokens(uint256 amountOut, address[] path, address to, uint256 deadline),
    • swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] path, address to, uint256 deadline),
    • swapExactETHForTokens(uint256 amountOutMin, address[] path, address to, uint256 deadline),
    • swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline),
    • swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline),
    • swap(string aggregatorId, address tokenFrom, uint256 amount, bytes data),
    • swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline),
    • swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline),
    • swapExactTempleForStable(uint256 amountIn, uint256 amountOutMin, address stable, address to, uint256 deadline)).
  • Console log Contract Address: console logs extracted contract address.

Installation

Install evm-input-data-decoder with npm

  npm install evm-input-data-decoder --save

Usage/Examples

//IMPORT METHOD
const decoder = require('evm-input-data-decoder');

//example input data you want to decode
const input = "0x7ff36ab5000000000000000000000000000000000000000000002d7c2e7091125587a8df0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000977223ef93b8490e8e6d2dc28567360f489a3ee100000000000000000000000000000000000000000000000000000000601892860000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000003affcca64c2a6f4e3b6bd9c64cd2c969efd1ecbe" // Example input from a transaction 


// Console Log Decoded Input Data
decoder.consoleLogDecodedInput(input)

// Console Log Contract Address
decoder.consoleLogGetContractAddress(input)

//decodes the transaction input data
decoder.decodeInput(input)
//returns an object of methodId String and input parameters Array

//gets the contract address
decoder.getContractAddress(input)
//returns CA: Contract Address
//DESTRUCTURING METHOD
// Import the necessary functions or features from the package
const { decodeInput, getContractAddress,consoleLogDecodedInput,consoleLogGetContractAddress } = require('evm-input-data-decoder');

//example input data you want to decode
const input = "0x7ff36ab5000000000000000000000000000000000000000000002d7c2e7091125587a8df0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000977223ef93b8490e8e6d2dc28567360f489a3ee100000000000000000000000000000000000000000000000000000000601892860000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000003affcca64c2a6f4e3b6bd9c64cd2c969efd1ecbe" // Example input from a transaction 


// Console Logs Decoded Input Data
consoleLogDecodedInput(input)

// Console Logs Contract Address Data
consoleLogGetContractAddress(input)

//decodes the transaction input data
decodeInput(input)
//returns an object of methodId String and input parameters Array

//gets the contract address
getContractAddress(input)
//returns CA: Contract Address

alt text

alt text

Appendix

This section provides a detailed breakdown of the main functions and utility functions available in the package.

decodeInput(input)

Purpose:

To decode Ethereum transaction input data.

Parameters:

input_data (String): The ABI encoded input data from a transaction.

Returns:

An object containing: methodId: A string representing the first 10 characters of the input data which usually represents the function signature.

params: An array containing parameters that have been extracted from the input data.

getContractAddress(input)

Purpose:

To identify and extract the token contract address from well-known function signatures within the provided ABI encoded data.

Parameters:

input_data (String): The ABI encoded input data from a transaction.

Returns:

One of the following: An object with a single key, "CA", that maps to the token contract address in the format "0x...token address...".

An error message stating the inability of the dependency to find the token contract address in the given input data.

Utility Functions:

consoleLogDecodedInput()

Purpose:

To decode the ABI encoded input data and print the results to the console.

Usage:

Call the function directly without any parameters to see the decoded input printed to the console.

consoleLogGetContractAddress()

Purpose:

To decode the ABI encoded input data to identify and extract the token contract address and then print either the address or an error message to the console.

Usage:

Call the function directly without any parameters to see the extracted token contract address or the relevant error message printed to the console.

Contributors

License

MIT

Disclaimer

Please make sure to test this library extensively before using it in a production environment. Ensure the decoded data and extracted addresses align with your expectations.