docs(27_ABIEncode): add abi.encodeCall tutorial and example - #912
Open
xuyua9 wants to merge 1 commit into
Open
Conversation
Closes AmazingAng#801. Add a fifth ABI encoding function, abi.encodeCall, to the 27_ABIEncode chapter. abi.encodeCall takes a function pointer and a tuple of arguments, and performs compile-time checks on the function signature and parameter types, making it safer than hand-written signatures used by abi.encodeWithSignature / abi.encodeWithSelector. - 27_ABIEncode/ABIEncode.sol: add foo() stub and encodeCall() example - 27_ABIEncode/readme.md: refresh intro (4 -> 5 functions) and add a dedicated abi.encodeCall section - Languages/pt-br/27_ABIEncode/{ABIEncode.sol,readme.md}: mirror the same changes for the Portuguese localization The encoded calldata matches the existing abi.encodeWithSignature("foo(uint256,address,string,uint256[2])", ...) example used earlier in the chapter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & Why
Closes #801.
abi.encodeCallis the compile-time-checked counterpart ofabi.encodeWithSignature/abi.encodeWithSelector. Issue #801 asks for it to be added to the 27_ABIEncode chapter, and provides the canonical example.This PR adds the fifth ABI encoding function to the chapter:
27_ABIEncode/ABIEncode.sol: add afoo(uint256,address,string,uint256[2])stub and anencodeCall()example that mirrors the existingencodeWithSignature/encodeWithSelectorexamples (samex,addr,name,arraystate).27_ABIEncode/readme.md: refresh the intro (4 -> 5 functions) and add a dedicated### abi.encodeCallsection that explains the compile-time signature/type check and that the calldata matchesabi.encodeWithSignature("foo(uint256,address,string,uint256[2])", ...).Languages/pt-br/27_ABIEncode/{ABIEncode.sol,readme.md}: mirror the same code and readme changes for the Portuguese localization, keeping the chapter in sync across translations.The chapter structure and example style are unchanged; only the new section is appended between
abi.encodeWithSelectorandabi.decode.Type of PR
Refs
abi.encodeCall#801encodeWithSignature,encodeWithSelectorin27_ABIEncode/ABIEncode.sol.