Code Monkey home page Code Monkey logo

ethereum-tx-sign's Introduction

ethereum-tx-sign

Build Status

Allows you to sign Ethereum transactions offline.

// 1 mainnet, 3 ropsten
const ETH_CHAIN_ID: u32 = 3;

let tx = ethereum_tx_sign::RawTransaction {
    nonce: web3::types::U256::from(0),
    to: Some(web3::types::H160::zero()),
    value: web3::types::U256::zero(),
    gas_price: web3::types::U256::from(10000),
    gas: web3::types::U256::from(21240),
    data: hex::decode(
        "7f7465737432000000000000000000000000000000000000000000000000000000600057"
    ).unwrap(),
};

let mut data: [u8; 32] = Default::default();
data.copy_from_slice(&hex::decode(
    "2a3526dd05ad2ebba87673f711ef8c336115254ef8fcd38c4d8166db9a8120e4"
).unwrap());
let private_key = web3::types::H256(data);
let raw_rlp_bytes = tx.sign(&private_key, &ETH_CHAIN_ID);

let result = "f885808227108252f894000000000000000000000000000000000000000080a\
    47f746573743200000000000000000000000000000000000000000000000000\
    00006000572aa0b4e0309bc4953b1ca0c7eb7c0d15cc812eb4417cbd759aa09\
    3d38cb72851a14ca036e4ee3f3dbb25d6f7b8bd4dac0b4b5c717708d20ae6ff\
    08b6f71cbf0b9ad2f4";
assert_eq!(result, hex::encode(raw_rlp_bytes));

That's it!

ethereum-tx-sign's People

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.