6

I am trying to build a light interface which can broadcast a raw transaction and execute an Ethereum contract's function. While I am able to build a simple transaction there is little guidance on how to execute a contract's function.

I have the following code to build the transaction:

function createRawTransacton(){
var privateKey = new Buffer('d3780dd620ef80b3918dfcdb9105f76147fc55a3775ff71805ccec09a89063ed', 'hex')
 var rawTx = {
   nonce: 'CX350',
   gasPrice: 'C350',
   gasLimit: '0x09184e72a000',
   to: '0xc5622be5861b7200cbace14e28b98c4ab77bd9b4',
   value: 'CX350',
   data:    '0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f'
}
var tx = new Tx(rawTx)
tx.sign(privateKey)
var serializedTx = tx.serialize()
console.log(serializedTx.toString('hex'))
broadCastTx(serializedTx.toString('hex'))
}
  • It's against the policy of the stack exchange network to crosspost questions on multiple subsites. Please, for future questions, consider if you want to post them here or on stackoverflow, but please don't post it on both sites. – Waqar Lim Jul 7 '16 at 8:54
  • How to get private key . or there can be any 32 bit hash as private key . – Himanshu sharma Mar 2 '17 at 7:11
4

The to field needs to be the address of the contract that you want to invoke. Then, in the data field, you encode the function you are invoking and its arguments, according to the ABI. It will be easier to use web3.js, such as its Contract Methods, instead of a raw transaction (that's why there are abstractions over the raw material).

  • Hmm, I realise web3 is easier but I need it to be light and not dependant on a node. Web3 requires a full node and that won't work with my hardware hence the raw transaction – Jim Jul 7 '16 at 8:06
  • @Jim You don't need a node, just install Metamask Chrome extension, or run geth in light mode (if you need the main network). For development, you can use Truffle and have your local node without much hardware requirement. – ulu Nov 6 '17 at 12:38
0

https://medium.com/@607ba26a48be/8d6cc8174c5d

Check this link. I have code written in golang to create offline transactions

  • Hi. Can you summarise what you did in your answer? Link-only answers are discouraged because the link could go dead/missing at any time. – Richard Horrocks Dec 13 '17 at 20:02

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.