5

What's the simplest way of executing piece of code at specific address of the main blockchain locally using the command-line interface?

In here it's demonstrated how to play mp3 file based on the input data using geth command, but how can you execute the actual code with its logic on your local machine for own testing purposes?

  • Can you elaborate / try to clarify what you mean. I'm having trouble figuring out exactly what you want to have happen. – tayvano May 6 '16 at 2:23
  • I just want to simulate the execution of the bytecode at the specific blockchain address. I think the current answer covers that. – kenorb May 6 '16 at 8:35
  • What do you mean by simulate ? Do you want to use the live main blockchain or a test one as testrpc can provide ? Then the example of the MP3 is just a data stored in a transaction. Do you mean reading a binary data stored in a transaction and then directly use it out of standard output and run it in some other local program (here mpg321 to play the mp3 binary data). What sort of data do you plan to store ? Be aware of the cost of storing data in the chain. You'd better use some distributer FS like IPFS and create a link to the content in the transaction data. – Nicolas Massart May 7 '16 at 10:13
  • I mean I'd like to simulate execution of already existing code in the blockchain on my local machine from CLI. Not reading the data like audio, but to execute the bytecode and get the result of that execution just for testing purposes. I'm not planning to store anything in the main blockchain, I may want to store the data in some temporary place in order to execute the code. – kenorb May 7 '16 at 20:44
7

The JSON_RPC eth_call method allows you to simulate a transaction on the blockchain, including contract executions.

This method can be accessed in geth or web3.js as

eth.call({from: eth.accounts[0], to: myContract, gas: 1000000, value: web3.toWei(1,"ether")})

If you know the ABI for a contract, you can use

var myContract = eth.contract(myABI).at(contractAddress);
var result = myContract.myMethod.call(arg1,arg2,arg3,{from:myAddress, gas:1000000})

If you want to get a debugging trace of a transaction, you can send a transaction, then use debug_traceTransaction.

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.