1

I have two question about how can I send ethereum programmatically.

1. How can I use the https://api.myetherapi.com/ropsten address to test my code?

I tried something like this:

...
web3 = new Web3(newWeb3.providers.HttpProvider("https://api.myetherapi.com/ropsten?apikey=mykey"));
...

But I get this response: {"message":"Missing Authentication Token"}

Do api.myetherapi.com and ropsten.infura.io uses the same ledger?


2. I cannot send any ETH over Ropsten network. For this one I use infura.io, and whatever I try, is not working. Here is my code:

    var Web3 = require('web3');

    if (typeof web3 !== 'undefined') {
      web3 = new Web3(web3.currentProvider);
    } else { 
      web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/DvTaqzNZpFvErBoHkvwL"));   // SANDBOX
    }

    var txDecoder = require('ethereum-tx-decoder');

    gasPrice = 0;
    web3.eth.getGasPrice(function(error, result) {
            console.log('Gas Price: '+ result);
            gasPrice = result;

            const ethTx = require('ethereumjs-tx');

            const txParams = {
                      nonce: '1',           // Replace by nonce for your account on geth node
                      gasPrice: gasPrice,   // maximum price of gas you are willing to pay for this transaction
                      gasLimit: 0.0000001,  // maximum gas you are willing to pay for this transaction
                      to: '0xb8412c93aefe25937d1f5f43393d6d74382ae987',
                      value: 0.000000001,
            };

            // Transaction is created
            const tx = new ethTx(txParams);
            const privKey = Buffer.from('7dc2...private_key', 'hex');

            // Transaction is signed
            tx.sign(privKey);
            const serializedTx = tx.serialize();
            const rawTx = '0x' + serializedTx.toString('hex');
            console.log(rawTx);
            console.log(txDecoder.decodeTx(rawTx));


            web3.eth.sendSignedTransaction(rawTx, function(err, hash) {
                    if (!err) {
                            console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
                     } else {
                            console.log(err)
                      }
            });

    });

My private key is related to this: https://ropsten.etherscan.io/address/0x25D8A20E97fE8af009e9A67eE5DBd4bB92751d9a - where I have 20 ETH

All the errors I get are related with the gas price/limit, or the transaction is not mined in the next 50 blocks.

Thanks in advance!

1

Per myetherapi.com, I think you want https://api.myetherapi.com/rop:

web3 = new Web3(newWeb3.providers.HttpProvider("https://api.myetherapi.com/rop"));

The nonce should be 0 for that account, the gasLimit needs to be at least 21000 (the base limit for a transaction), and value should be expressed in wei:

const txParams = {
  nonce: 0,             // Replace by nonce for your account on geth node
  gasPrice: gasPrice,   // maximum price of gas you are willing to pay for this transaction
  gasLimit: 21000,      // maximum gas you are willing to pay for this transaction
  to: '0xb8412c93aefe25937d1f5f43393d6d74382ae987',
  value: web3.toWei(0.000000001, "ether"),
};
  • As I understand, the nonce is the number of transactions from my address. Why this should be 0 if i have 5 transactions? ropsten.etherscan.io/address/… If I use your example, I get Error: Returned error: insufficient funds for gas * price + value even if web3.eth.getBalance returns 20010300432005200000 – Liviu A. Feb 21 '18 at 12:30
  • It's the number of transactions that have been sent from that address. What's the value of gasPrice? – smarx Feb 21 '18 at 13:00

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.