How can I run function in a contract by evm?

152 Views Asked by At

I'm a newbie in solidity and Ethereum. I build the evmc project on github to run my smart contract locally.

I first compile my contract by solc and use the following command:

solc --abi --asm --hashes --bin --overwrite -o . hello.sol

Here is my contract hello.sol:

pragma solidity >0.4.0;

contract HelloWorld{
  uint a;
  uint b;
  function renderHelloWorld () public returns (uint256) {
    a = 0;
    b = a+3;
    return b;
  }
}

I generate the bytecode successfully, and I use evmc to run this contract by following command:

./build/evmc/bin/evmc --vm build/evmc/examples/example_precompiles_vm/libexample-precompiles-vm.dylib run HelloWorld.bin

And get this result:

Config: build/evmc/examples/example_precompiles_vm/libexample-precompiles-vm.dylib
Executing on Istanbul with 1000000 gas limit

Result:   success
Gas used: 0
Output:

I've noticed that the gas I used is 0, but the result of this contract is Success. I guess that contract may not been run correctly. And there are few questions.

  1. Do I really success to run this contract?
  2. How can I print my return value b in this contract?
  3. How does evm find and run the function in contract? (There are an option --input in the ./build/evmc/bin/evmc file, I tried to put the renderHelloWorld() 's signature opcode 942ae0a7 after this option. But the result is the same.)
  4. If I build an function needs some input, how can I give these input values?

Thank you in advance.

0

There are 0 best solutions below