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

decode-transaction-simulation

v1.1.0

Published

An npm package to decode web3 transaction using simulation

Downloads

6

Readme

decode-transaction-simulation

Overview

The decode-transaction-simulation package helps you decode transaction data from the Tenderly API and extract information about asset changes.

Features

Decode Tenderly Transaction Data: Simplifies decoding transaction data retrieved from the Tenderly API. Identify Asset Changes: Analyzes transactions to identify token transfers (inflow/outflow) and their details. Error Handling: Provides informative error messages in case of decoding issues or API errors.

Installation

Install the package using npm:

npm install decode-transaction-simulation

Usage

Step 1: Import the Class

Import the Decoder class in your JavaScript or TypeScript file:

import Decoder from 'decode-transaction-simulation';

Step 2: Provide Tenderly Credentials

Getting Tenderly API Keys, Project, and Account Slug

Sign Up on Tenderly:

Visit Tenderly Registration to sign up.

Access Settings:

After logging in, navigate to the dashboard. At the bottom of the left sidebar, you will find the Settings option.

Locate API Keys and Slugs:

In the Settings section, you will find your personalized API keys, account slug, and project slug. You need your Tenderly account details to use the API. Create a .env file in your project root and add the following environment variables:

TENDERLY_ACCOUNT_SLUG=your_account_slug
TENDERLY_PROJECT_SLUG=your_project_slug
TENDERLY_ACCESS_KEY=your_access_key

Step 3: Instantiate the Decoder

Load the environment variables and create an instance of Decoder:

import dotenv from 'dotenv';
dotenv.config(); // Load environment variables

const provider = {
  TENDERLY_ACCOUNT_SLUG: process.env.TENDERLY_ACCOUNT_SLUG,
  TENDERLY_PROJECT_SLUG: process.env.TENDERLY_PROJECT_SLUG,
  TENDERLY_ACCESS_KEY: process.env.TENDERLY_ACCESS_KEY,
};

const decoder = new Decoder(provider);

Step 4: Decode a Transaction Create a transaction object and decode the transaction data:

const transaction = {
  network_id: 1, // Chain ID (e.g., 1 for Ethereum mainnet)
  from: '0x...', // Sender address
  to: '0x...', // Receiver address
  input: '0x...', // Input data
  gas: 21000, // Gas limit
  gas_price: 1000000000, // Gas price (in Wei)
  value: 0, // Transaction value (in Wei)
  simulation_type: 'quick', // Optional simulation type ('quick' or 'full')
};

decoder.decodeData(transaction)
  .then(data => {
    console.log(data); // Output decoded data
  })
  .catch(err => {
    console.error(err); // Handle errors
  });

Note: Replace the placeholder values in the transaction object with your actual transaction data.

Decoded Data Format

The decodeData method resolves with an object containing information about the transaction:

{
  "type": "Trade" // or details about token transfers
  "tokenIn": {
    "name": "Token Name",
    "symbol": "Token Symbol",
    "amount": "Token Amount",
    "decimal": "Token Decimal",
    "token_address": "Token Address",
    "type": "Token type",
    "standard": "Token Standard",
    "dollarValue": "Token DollarValue",
    "image":"Token Image"

  },
  "tokenOut": {
     "name": "Token Name",
    "symbol": "Token Symbol",
    "amount": "Token Amount",
    "decimal": "Token Decimal",
    "token_address": "Token Address",
    "type": "Token type",
    "standard": "Token Standard",
    "dollarValue": "Token DollarValue",
    "image":"Token Image"
  }
}

type: Indicates the type of transaction (e.g., "Smart contract Execution" or details about token transfers). tokenIn (optional): If tokens are transferred into the address, details about the incoming token (name, symbol, amount, etc.) are provided. tokenOut (optional): If tokens are transferred out of the address, details about the outgoing token (name, symbol, amount, etc.) are provided.

Contributing

We welcome contributions to this package! Please refer to the contributing guidelines (to be added in the future) for details on how to submit pull requests.