evm icon indicating copy to clipboard operation
evm copied to clipboard

Example of usage

Open b00f opened this issue 6 years ago • 4 comments

Is there any example of how to use this library?

b00f avatar Nov 07 '19 08:11 b00f

A related question is what functionality does the library actually provide (or plans to provide)?

For example, I want to write a testerchain that would take a JSON RPC request, like a regular node or some provider like Infura, and return a JSON RPC response like a node would. What part of it would be handled by evm?

Naturally I would handle serialization/deserialization to some typed values before passing them to evm. Managing filters would probably be my job too. But I am unclear about the basic functionality:

  • Contract calls - seems to be handled by https://docs.rs/evm/latest/evm/fn.transact.html with TransactArgsCallCreate::Call
  • Contract deployment - one would think transact() with TransactArgsCallCreate::Create, but I don't see any signature data there. Does that mean that checking transaction signatures is not done within evm?
  • Transfers - https://docs.rs/evm/latest/evm/backend/trait.RuntimeBackend.html#method.transfer ?
  • Contract transactions (that is, mutating calls) - ???
  • Block mining - ???
  • Transactions/blocks lookup by hash - ???

fjarri avatar Sep 19 '25 20:09 fjarri

The jsontests crate is probably the best way to understand example usage of this crate: https://github.com/rust-ethereum/evm/blob/master/jsontests/src/run.rs#L348

evm handles all the way up to contract transactions, but without the signature -- you first verify the signature (probably via the ethereum crate) and then pass the verified sender argument to evm. It does not do block mining or transaction/block lookup.

  • Contract calls: yes this is correct.
  • Contract deployment: yes, transact/TransactArgsCallCreate::Create handles this. It does not do transaction signature verification. Verify it first, and then pass the verified arguments to evm.
  • Transfers: the same as contract calls, so transact/TransactArgsCallCreate::Call.
  • Contract transactions: also simply contract calls, so transact/TransactArgsCallCreate::Call.
  • Block mining: evm does not do that. Just increase the coinbase balance and you're done. Note that evm handles transaction fee payment as part of the contract transaction.
  • Transactions/blocks lookup by hash: evm does not do that. This mapping needs to be stored externally.

sorpaas avatar Sep 19 '25 22:09 sorpaas

Thank you for the explanation. Are there any plans within the org to add a crate that would handle these higher level tasks, block generation in particular?

The jsontests crate is probably the best way to understand example usage of this crate

That's what I've been using so far. While it may be the best way available, it's certainly not the best possible - there's a lot of indirection happening, and even finding a relevant test among the hundreds of obscure JSON files with no comments is problematic.

fjarri avatar Sep 19 '25 22:09 fjarri

Are there any plans within the org to add a crate that would handle these higher level tasks, block generation in particular?

Yeah it'll be done by the ethereum crate. Note that ethereum crate is not yet ready for v1.0 and the interface will likely vastly change.

This separation of functionality is because many custom chains may not be using Ethereum signatures.

While it may be the best way available, it's certainly not the best possible - there's a lot of indirection happening, and even finding a relevant test among the hundreds of obscure JSON files with no comments is problematic.

I agree. The crate desperately lacks documentations and I'm working on this. :)

sorpaas avatar Sep 19 '25 22:09 sorpaas