6

I am looking for a way to execute current pending transactions on local node, to see their outcome and log events, without really mine it.

it is some kind of pre-simulation, to see what is going to happen on the next block in the network.

is it possible? how can it be done?

Or Bachar
  • 357
  • 5
  • 13

2 Answers2

5

You can totally simulated the transaction througth eth_call.

Her are the code snippets of eth_call and apply transaction (source from go-ethereum):

eth_call (could not change state)

// Setup the gas pool (also for unmetered requests)
// and apply the message.
gp := new(core.GasPool).AddGas(math.MaxUint64)
res, gas, failed, err := core.ApplyMessage(evm, msg, gp)
if err := vmError(); err != nil {
    return nil, 0, false, err
}
return res, gas, failed, err

apply transaction (could update state)

_, gas, failed, err := ApplyMessage(vmenv, msg, gp)
if err != nil {
    return nil, 0, err
}
// Update the state with pending changes
var root []byte
if config.IsByzantium(header.Number) {
    statedb.Finalise(true)
} else {
    root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
}

Remember to return the result of simulation when you use eth_call.

The solidity function looks like:

function simulation() pure public returns(bool result) {
    result = doSimulation();
}
Peter Lai
  • 317
  • 1
  • 3
  • Thanks! thats help, is there a way to access the event logs that happens during the transaction call? – Or Bachar May 10 '19 at 07:20
  • 3
    The event was written to receipt when transaction was included. https://github.com/ethereum/go-ethereum/blob/master/core/state_processor.go#L122 – Peter Lai May 10 '19 at 08:13
2

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

From : How can I execute code locally at given address?

Archi
  • 379
  • 1
  • 6