9

I installed and used ethereumjs-tx, as explained here.

I ran the following commands:

var Tx = require('ethereumjs-tx')
var privateKey = new Buffer('xxxxxxxxx', 'hex')

var rawTx = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000', 
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000', 
  value: '0x00', 
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}

var tx = new Tx(rawTx)
tx.sign(privateKey)

var serializedTx = tx.serialize()

Now, how do I broadcast this transaction to the testnet?

If relevant, I have a geth node running and synced, with an etherbase. Do I need to somehow use geth to send this transaction, or can I send it just with ethereumjs libraries, and (in either way) how can I do it?

Thanks for any help,

4

I believe that you are looking for this:

https://github.com/ethereum/wiki/wiki/JavaScript-API#example-45

check it once.

3

If you are using JSON-PRC and web3:

If you need to use a public API service (e.g. Etherscan) it proxyes raw send

3

Here's an example on how to do it from the web3 documentation:

var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('xxxxxxxxxxx', 'hex')

var rawTx = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000', 
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000', 
  value: '0x00', 
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}

var tx = new Tx(rawTx);
tx.sign(privateKey);

var serializedTx = tx.serialize();

//console.log(serializedTx.toString('hex'));
//0xf889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f

web3.eth.sendRawTransaction(serializedTx.toString('hex'), function(err, hash) {
  if (!err)
    console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
});

SOURCE

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.