函数选择器

- 1 min

ABI,函数签名和函数选择器

ABI

应用二进制接口

四个场景

函数选择器(也叫函数签名)

byte4 selector = contract.value.selector
bytes memory data = abi.encodeWithSelector(selector, param1)
(bool suc, bytes memory returnedData) = address(contract).call(data)
require(suc)

return abi.decode(returnedData, (uint256))

delegatecall

delegatecall is a low level function similar to call.

When contract A executes delegatecall to contract B, B’s code is executed

with contract A’s storage, msg.sender and msg.value.

A合约使用delegatecall调用b合约

b合约的代码被执行了, 但是带上的msg.sender, msg.vaue和storage都是a合约的.