GithubHelp home page GithubHelp logo

yamenmerhi / nick-method Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 321 KB

NPM package that facilitates generating transactions following Nick-Method and utilities functions.

JavaScript 98.61% Solidity 1.39%

nick-method's Introduction

⚠️ ⚠️ Migrated ⚠️⚠️

This repo has been migrated to @PatronumLabs/nick-method

nick-method

A package that offers various options for creating transactions in accordance with the nick method, as well as utility functions for recovering transactions and sender addresses from raw transactions.

To learn more about Nick's method, read this article: Nick's method - Ethereum Keyless Execution

Note: Currently, only legacy transactions (type 0) are supported. Type 1 and 2 will be added soon.

This package is in testing phase, please test on testnets before applying in production.

Usage

npm

$ npm install nick-method

API

const nickMethod = require("nick-method");

const txParams = nickMethod.generateTypeZeroTxJSONFromParams(nonce, gasPrice, gasLimit, value, data, optionalParameters);

const transactionConfig = nickMethod.generateTypeZeroTxNickMethodConfig(txParams);

const deploymentConfig = nickMethod.generateNickMethodConfigForContractDeployment(txParams);

const executionCost = nickMethod.getTypeZeroTxExecutionCost(txParams);

const gasCost = nickMethod.getTypeZeroTxGasCost(txParams);


// Utilities:

isProtectedTx(..)
isProtectedRawTx(..)
recoverSenderFromRawTx(..)
getTxType(..)

Soon

Detailed documentation about how to use each function will be available soon under ./docs.

Multi-chain deployment on the same address

Generate txParams

const nickMethod = require("nick-method");

let txParams = {
  nonce: 0,  // nonce should be 0
  value: 0,
  gasPrice: 1000000000000, // gasPrice should be taken into consideration for future 
  gasLimit: 1000000, // gasLimit for the deployment
  data: "0xab11ffcc.......", // bytecode + constructor argument encoded if present
};

Generate config

const config = nickMethod.generateNickMethodConfigForContractDeployment(txParams);

> {
  rawTx: '0xf9047c8085e8d4a51000830f42408080b90429.............',
  deployerAddress: '0x62d517a7451007232d2f1DDE6385882DdC293F26',
  contractAddress: '0xE8cE8c9d71f98893B39286D382eEA3B94010A020',
  gasPrice: '0xe8d4a51000',
  gasLimit: '0xf4240',
  r: '0x1212121212121212121212121212121212121212121212121212121212121212',
  s: '0x1811fb2e72af1eee2210a2bab6f93da5490cbfe935568afd461f9bf5e2c76151',
  v: '0x1b'
}

Funding deployer Address

Fund the deployerAddress with the necessary cost value + gasPrice * gasLimit,can be calculated with getTypeZeroTxExecutionCost(txParams).

Broadcasting the rawTx to the network

Connect to networks nodes that allow unprotected tx.

const Web3 = require("web3");

// These networks support Unprotected tx such as alfajores-celo, l14-LUKSO, binance testnet.

// const web3 = new Web3('https://celo-alfajores.infura.io/v3/{API}');
// const web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545/');
// const web3 = new Web3('https://rpc.l14.lukso.network');

Execute the script below with uncommenting the intended network to deploy on:

const Web3 = require("web3");
// const web3 = new Web3('https://celo-alfajores.infura.io/v3/{API}');
// const web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545/');
// const web3 = new Web3('https://rpc.l14.lukso.network');

const rawTx = "0xf9047c8085e8d4a51000830f42408080b90429...."; // Paste the full rawTx here

async function sendRawTx() {
  await web3.eth.sendSignedTransaction(rawTx).on("receipt", console.log);
}

sendRawTx();

Contract deployed

The contract deployed will be created on the contractAddress pointed by the config generated from generateNickMethodConfigForContractDeployment(..) function. The script above can be executed on several networks and the resultant contract address will be the same as long as the deployer address is funded.

nick-method's People

Contributors

yamenmerhi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  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.