Coder Social home page Coder Social logo

drydragon10 / js-direct-route Goto Github PK

View Code? Open in Web Editor NEW

This project forked from node-real/js-direct-route

0.0 0.0 0.0 52.56 MB

A JS thin wrapper around the Direct Route API

License: Other

JavaScript 85.36% TypeScript 13.30% Makefile 0.02% Shell 1.08% HTML 0.08% Solidity 0.16%

js-direct-route's Introduction

JS SDK of DirectRoute

What is Direct Route

NodeReal MEV is a permissionless, transparent service for efficient MEV extraction on EVM blockchains. It achieves following goals:

  1. Transaction privacy. Transactions submitted through MEV can never be detected by others before they have been included in a block.
  2. First-price sealed-bid auction. It allows users to privately communicate their bid and granular transaction order preference.
  3. No paying for failed transactions. Losing bids are never included in a block, thus never exposed to the public and no need to pay any transaction fees.
  4. Bundle transactions. Multiple transactions are submitted as a bundle, the bundle transactions are all successfully validated on chain in the same block or never included on chain at all.
  5. Efficiency. MEV extraction is performed without causing unnecessary network or chain congestion.

Installation

Node

npm install @node-real/web3

Yarn

yarn add @node-real/web3
npm run build

Usage

  1. Init Client
// Init client
const Web3 = require('@node-real/web3');

var directRouteEndPoint = "https://api.nodereal.io/direct-route";
let web3 = new Web3(directRouteEndPoint);
  1. Query suggested bundle price var price = await directClient.eth.getBundlePrice();

  2. Send bundle

const tx1 = {
        'from': account1,
        'to': account2,
        'gas': 23000,
        'gasPrice': price,
        'data': rpcClient.utils.toHex(data1),
        'chainId': 56,
    };
const tx2 = {
    'from': account2,
    'to': account1,
    'gas': 23000,
    'gasPrice': price,
    'data': rpcClient.utils.toHex(data2),
    'chainId': 56,
};

const privateKey1 = '';
const privateKey2 = '';
const signedTx1 = await rpcClient.eth.accounts.signTransaction(tx1, privateKey1);
const signedTx2 = await rpcClient.eth.accounts.signTransaction(tx2, privateKey2);

var myDate = new Date();
const maxTime = Math.floor(myDate.getTime() / 1000) + 80;
const minTime = Math.floor(myDate.getTime() / 1000) + 20;

console.log(maxTime, minTime);

const bundleArgs = {
    'txs': [signedTx1.rawTransaction, signedTx2.rawTransaction],
    'minTimestamp': minTime,
    'maxTimestamp': maxTime,
    'revertingTxHashes': [signedTx2.transactionHash],
};
const bundleHash = await directClient.eth.sendBundle(bundleArgs);

After the bundle is successfully submitted, you may need wait at lest 3-60 seconds before the transaction been verified on chain

  1. Query bundle

    const queryBundle = await directClient.eth.getBundleByHash(bundleHash);

  2. Get Status of Validators

    var status = await directClient.eth.getValidatorStatus();

SDK example

  1. getBundlePriceDemo. The bundle price is volatile according to the network congestion, the demo shows you how to get proper bundle price.
  2. getValidatorsStatusDemo. The demo shows how to get status of Validators.
  3. sendBUSDByBundleDemo. In this case, we use two accounts to send BUSD to each other, the second transaction is allowed to be failed, and the bundle should be verified on chain during [now+20 second, now+80 second]. This case shows you how to interact with smart contract through direct-route, and how to control the timing to be verified.

If you want to try with above examples, what you need to do is just to replace the account address of account1 and account2 in bundle_example.js and private keys of privateKey1 and privateKey2.

Building

Requirements

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

js-direct-route's People

Contributors

bethnull avatar cgewecke avatar chevdor avatar cruzmolina avatar cryyl avatar cubedro avatar debris avatar dependabot[bot] avatar ethers avatar ewingrj avatar frankiebee avatar frozeman avatar gabmontes avatar gavofyork avatar gregthegreek avatar helderjnpinto avatar holgerd77 avatar joshstevens19 avatar kumavis avatar lefterisjp avatar lihengl avatar nachomazzara avatar nimishbongale avatar nivida avatar nujabes403 avatar obscuren avatar princesinha19 avatar ryanio avatar shayanb avatar spacesailor24 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.