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

Contract calldata api #349

Merged
merged 2 commits into from May 27, 2020
Merged

Contract calldata api #349

merged 2 commits into from May 27, 2020

Conversation

0xdewy
Copy link
Contributor

@0xdewy 0xdewy commented May 27, 2020

Hey I wanted to use the library to construct calldata for contract functions, but I wasn't able to find anything.

I just did a quick change to see if I could expose the api for this, but I'm happy to clean it up if it makes sense.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for the PR, but I don't feel this suits the interface of web3. This can easily be done using ethabi directly.

I'm willing to accept a PR that simply exposes the ethabi::Contract reference, like so:

/// Get the underlying contract ABI.
pub fn abi(&self) -> &ethabi::Contract {
  &self.abi
}

With this you can get the call data via:

let bytes = contract.abi().function(func)?.encode_input(&params.into_tokens());

Also see #17 & #120

nonce,
condition,
} = options;
.unwrap()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is there for a reason, simply unwraping will cause panics in case the function is not found.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing me towards #17 .. ethabi_derive looks really nice 👌
Sorry about the unwrap() .. should have been an issue not a pull request 🙄

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries @kyledewy, thanks a lot for the contribution!

@tomusdrw
Copy link
Owner

Awesome, cheers!

@tomusdrw tomusdrw merged commit 69d5746 into tomusdrw:master May 27, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants