Skip to content

Instantly share code, notes, and snippets.

@bitgord
Created December 5, 2016 01:53
Show Gist options
  • Save bitgord/941bd44d72f5518e8ef8d3fe8898bf69 to your computer and use it in GitHub Desktop.
Save bitgord/941bd44d72f5518e8ef8d3fe8898bf69 to your computer and use it in GitHub Desktop.
Ethereal Mainnet Transactions
//First you need to get an API endpoint to the Ethereum mainnet from infura.io
var endpoint = "https://mainnet.infura.io/[[insert-passcode]]"
//Require and setup new Web3
var Web3 = require("web3")
var EthTx = require("ethereumjs-tx")
//Create two accounts from TestRPC
var acct1 = ""
var acct2 = ""
//Create object for raw Transaction
var rawTX = {
nonce: web3.toHex(web3.eth.getTransactionCount(acct1)),
to: acct2,
gasPrice: web3.toHex(21000000000),
gasLimit: web3.toHex(21000),
value: web3.toHex(web3.toWei(1, 'ether')),
data: ""
}
//Create var for private key
var pKey1 = ""
//Create buffer
var pKey1x = new Buffer(pKey1, 'hex')
//New transaction instance
var tx = new EthTx(rawTx)
//Sign transaction
tx.sign(pKey1x)
//Make Serialized
var serializedTx = `0x${tx.serialize().toString('hex')}`
//Send Transaction which returns hash of transaction on main network
web3.eth.sendRawTransaction(serializedTx, (error, data) => {
if(!error) { console.log(data) } else {console.log(error) }})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment