1

I was trying to follow: https://github.com/ThatOtherZach/Web3-by-Example/wiki/Send-Ether-Transaction to create and broadcast my first transaction on the ethereum testnet rinkeby.

However, I am struggling for hours after I managed to create an Address and to fund it (https://rinkeby.etherscan.io/address/0x24003FbB79cfA541eE32C59ef3A7424541f4AA01). I also tried the ropsten testnet, and with all possible gasPrice/gasLimit combinations (not even commenting them out helps) but same errors all the time:

Error: Returned error: exceeds block gas limit

My code:

 // Add the web3 node module
var Web3 = require('web3');

// Show web3 where it needs to look for the Ethereum node.
web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/Whm5Ks3VGzJMBGHh4MEx'));

// An extra module is required for this, use npm to install before running
var Tx = require('ethereumjs-tx');

// Used to sign the transaction. Obviously you SHOULD better secure this than just plain text
var privateKey = new Buffer('265f303edd16be057608a0810414c2889c24e7ce8e9e4a88ae5b8a561c26935a', 'hex');

 // The receiving address of the transaction
var receivingAddr = ('0x29307EE93F49E9eB1425e40C9119b9Cb6e39d9B5');

// Value to be sent, converted to wei and then into a hex value
var txValue = web3.utils.numberToHex(web3.utils.toWei('0.001', 'ether'));
console.log(txValue);
// Data to be sent in transaction, converted into a hex value. Normal tx's do not need this and use '0x' as default, but who wants to be normal?
var txData = web3.utils.asciiToHex('hi'); 

console.log('gasprice1');



var rawTx = {
  nonce: '1', // Nonce is the times the address has transacted, should always be higher than the last nonce 0x0#
  gasPrice: '0x38d7ea4c68000', // '0x14f46b0400', // Normal is '0x14f46b0400' or 90 GWei
  gasLimit: '2100000', //'0x2710', // Limit to be used by the transaction, default is '0x55f0' or 22000 GWei
  to: receivingAddr, // The receiving address of this transaction
  value: txValue, // The value we are sending '0x16345785d8a0000' which is 0.1 Ether
  data: txData // The data to be sent with transaction, '0x6f6820686169206d61726b' or 'oh hai mark' 
}

console.log(rawTx); // This is used for testing to see if the rawTx was formmated created properly, comment out the code below to use.


var tx = new Tx(rawTx);
tx.sign(privateKey); // Here we sign the transaction with the private key

var serializedTx = tx.serialize(); // Clean things up a bit

console.log(serializedTx.toString('hex')); // Log the resulting raw transaction hex for debugging if it fails to send

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')) // Broadcast the transaction to the network
.on('receipt', console.log); // When a receipt is issued, log it to the console

If I use the values from https://github.com/ethereumjs/ethereumjs-tx gasPrice: '0x09184e72a000', gasLimit: '0x2710', I get: Error: Returned error: intrinsic gas too low

Following error with this setup: { nonce: '0x00', gasPrice: '0x09184e72a000', gasLimit: '0x2710', from: '0xED54EbBC73C7fb8B6607547b7541D8799708D93B', to: '0xB29d0bDe21FF7f1a89eBEd0D9c40cA9f71119D7C', value: '0x38d7ea4c68000', chainId: '3', data: '0x737072656164' }

Error: Returned error: insufficient funds for gas * price + value

  • Starting this code with "node C:/Programs/code_snippets/create-wallet.js". – igotBAWS Jun 26 '18 at 1:33
  • Changed gasPrice: '0x38d7ea4c68000', gasLimit: '2100000', TO gasPrice: web3.utils.toHex(20000000000), gasLimit: web3.utils.toHex(800000), ´ Now nothing happens, no error no nothing : – igotBAWS Jun 28 '18 at 19:29
0

Changed gasPrice: '0x38d7ea4c68000', gasLimit: '2100000', TO gasPrice: web3.utils.toHex(20000000000), gasLimit: web3.utils.toHex(800000), ´ Now it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.