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!