I am reading an article, it says:
To enable deployment on the Ethereum platform, the contract functions
are compiled into EVM bytecode and a piece of code called function
selector is added, which serves as an entry point into the contract
code.
Can some body please tell me what is a function selector?
I tried google and found:
The first four bytes of the call data for a function call specifies
the function to be called. It is the first (left, high-order in
big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature
of the function. The signature is defined as the canonical expression
of the basic prototype without data location specifier, i.e. the
function name with the parenthesised list of parameter types.
Parameter types are split by a single comma – no spaces are used.
I can't understand what is call data?
Some body please guide me.
Zulfi.
Best Answer
A function selector allows you to perform dynamic invocation of a function, based on the name of the function and the type of each one of the input arguments.
For example, suppose you have:
Then you can call
Contract1.func
fromContract2.func
as follows:If the invoked function is constant (either
pure
orview
), then you can also usestaticcall
.The example above is in assembly, but you can also use
call
directly in solidity.I think that
staticcall
should be available starting from solidity v0.5.0.