1

I am working on university project and this is the only and last point i need your help. I want to call automatically a state-changing function in meteor without the submit confirmation in metamask. Therefore i read about using ethereumjs-tx but i don't know how to sign the method call to get this smart contract method automatically running. Pleas i can't find a answer anywhere: The current code i have in my script:

global.Buffer||require("buffer").Buffer;
const EthereumTx = require('ethereumjs-tx')
const privateKey = Buffer.from('my private key', 'hex')
const txParams = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000', 
  gasLimit: '0x2710',
  to: contractAdress, 
  value: '0x00', 
  data: contractdata,
  // EIP 155 chainId - mainnet: 1, ropsten: 3
  chainId: 3
}
const tx = new EthereumTx(txParams)
tx.sign(privateKey)
const serializedTx = tx.serialize()

How has the method call look like, something like this? myContractInstance.setFinised(true, what to insert here?, function(err, res){});

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

Here you will find example how to do it: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendrawtransaction

  • Be aware though, this is for ^0.17.0 beta. sendRawTransaction is not available in 1.0.0 beta – Florian Castelain Jan 16 '18 at 6:03
0

Not like that but you can call your function via data like enter image description here const txParams = { data: HERE, // EIP 155 chainId - mainnet: 1, ropsten: 3 chainId: 3 }

and then call

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

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.