Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to invoke a specified method of contract? #159

Closed
lowesyang opened this issue Nov 15, 2018 · 8 comments
Closed

How to invoke a specified method of contract? #159

lowesyang opened this issue Nov 15, 2018 · 8 comments

Comments

@lowesyang
Copy link

lowesyang commented Nov 15, 2018

ECI spec tells us that every contract will export a main function with no parameters and returns. But i have two questions:

  1. What's the main function generally for?
  2. If a contract has several methods, how can i invoke one of the methods with some parameters in eWASM, just like EVM1?
@axic
Copy link
Member

axic commented Nov 15, 2018

Currently it uses the same Contract ABI encoding design to be compatible with EVM.

e.g. the main function will use callDataCopy to retrieve the call data (input) as in EVM and use finish to return the output.

@lowesyang
Copy link
Author

Can i explicitly define the main function in the contract, and how? It's better to have some examples~

@axic
Copy link
Member

axic commented Nov 15, 2018

I agree, we're working on the documentation at https://github.com/ewasm/testnet which should include these.

Here's an example contract in Rust: https://github.com/ewasm/ewasm-precompiles/blob/master/sha256/src/lib.rs

@lowesyang
Copy link
Author

lowesyang commented Nov 15, 2018

So main function may do the things below:

  1. retrieve the call data(input)
  2. decode the hex code of contract method from the input. e.g. 0xedfdfdfd with 4 bytes.
  3. call the func referenced by the above hex code
  4. use finish to return the output.

is that right?

@axic
Copy link
Member

axic commented Nov 15, 2018

Correct, it has to implement ABI handling on its own. Just like it is happening in EVM at the moment.

We're exploring other options though, see the umbrella issue #1

@lowesyang
Copy link
Author

Got that, thanks very much!
Maybe an automatically ABI handling just like in EVM is very in need, cause developers don't need to write the dispatcher themselves~

@lrettig
Copy link
Member

lrettig commented Mar 10, 2019

Can we close in favor of #1? Let's continue the conversation there

@axic
Copy link
Member

axic commented Mar 10, 2019

We'd need to document this for clarity though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants