Last active
August 2, 2018 19:31
-
-
Save tim-br/80e243efaa034599c2fd9d79bde47367 to your computer and use it in GitHub Desktop.
Generating a raw transaction using ethers.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ethers = require('ethers'); | |
var Wallet = ethers.Wallet; | |
var utils = ethers.utils; | |
var privateKey = '<privatekey>' | |
var wallet = new ethers.Wallet(privateKey); | |
var transaction = { | |
// needs to be greater than the nonce of the previous tx | |
// from this wallet | |
// can skip values | |
nonce: 1393251, | |
gasLimit: 21000, | |
gasPrice: utils.bigNumberify("20000000000"), | |
to: "0x9fa69Ec8D66fE3988b8f187C8F5cE2c5cCe95Ebd", | |
value: utils.parseEther("0.0001"), | |
// optional | |
data: "0x", | |
// This ensures the transaction cannot be replayed on different networks | |
// ropsten network | |
chainId: 3 | |
}; | |
var signedTransaction = wallet.sign(transaction); | |
console.log(signedTransaction) | |
// this will console out the raw transaction which can then be broadcasted on | |
// etherscan etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment