GithubHelp home page GithubHelp logo

express-multichain-gas-estimation-middleware's Introduction

EVM Gas Estimation Middleware for Express.js

This middleware provides functionality to estimate gas costs of EVM transactions in Express.js applications. It integrates with the multichain-evm-gas-estimator package to accurately estimate gas costs based on provided transaction details.

Installation

To install the EVM Gas Estimation Middleware, you can use npm:

npm install express-multichain-gas-estimation-middleware

Usage

  1. Import the EVM Gas Estimation Middleware into your Express.js application:
const express = require("express");
const app = express();
const gasEstimationMiddleware = require("express-multichain-gas-estimation-middleware");

// Middleware to parse JSON requests
app.use(express.json());

// Use EVM Gas Estimation Middleware
app.use(gasEstimationMiddleware);

// Route to handle incoming EVM transaction requests
app.post("/transaction", (req, res) => {
  // Access gas estimation data from the request object
  const gasEstimation = req.EVMGasEstimation;

  // Respond with gas estimation data
  res.status(200).json({ gasEstimation });
});

// Start the server
const PORT = process.env.PORT || 9000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
  1. Send POST requests to the /transaction endpoint with EVM transaction details in the request body. The middleware will estimate gas costs and attach the estimation data to the request object. The route handler can then access this data and respond accordingly.

Middleware Documentation

The EVM Gas Estimation Middleware is designed to estimate gas costs for EVM transactions. Here's how it works:

  • The middleware intercepts incoming requests to your Express.js application.
  • It extracts EVM transaction details from the request body, including the chain, Infura API key, transaction details (txDetails), and gas unit (unit).
  • Using the multichain-evm-gas-estimator package, it estimates the gas cost for the transaction.
  • The gas estimation data is attached to the request object as req.EVMGasEstimation.
  • The middleware handles errors during gas estimation and responds with a 500 status code and an error message if necessary.

Contributions and Issues

Feel free to contribute to this project or report any issues on the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.


This README provides an overview of the EVM Gas Estimation Middleware and demonstrates how to integrate it into your Express.js applications for accurate gas cost estimation in EVM transactions.

express-multichain-gas-estimation-middleware's People

Contributors

peppyeben avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.