在vyper中,encodeWithSelector (来自固体)的等价性是什么?
例如,在可靠的情况下,如果我想使用原始调用直接在我们自己的合同上使用transfer函数,我会这样做:
function callTransferFunctionDirectly(address someAddress, uint256 amount)
public
returns (bytes4, bool)
{
bytes4 selector = bytes4(keccak256(bytes("transfer(address,uint256)")));
(bool success, bytes memory returnData) = address(this).call(
// getDataToCallTransfer(someAddress, amount);
abi.encodeWithSelector(selector, someAddress, amount)
);
return (bytes4(returnData), success);
}我在vyper怎么做?
是的,我知道我们会打电话给
transfer,因为它是自己的合同。但这是为了学习。
发布于 2022-08-01 17:21:57
您可以使用concat或_abi_encode进行abi.encodeWithSelector等效,并使用method_id函数获取函数选择器。
上述坚实度在vyper中的(近)等价性是:
@external
def callTransferFunctionDirectly(someAddress: address, amount: uint256) -> (Bytes[32])
call_data: Bytes[68] = _abi_encode(someAddress, amount, method_id=method_id("transfer(address,uint256)"))
response: Bytes[32] = raw_call(self, call_data, max_outsize=32)method_id:给你选择器raw_call:是.call等价吗?_abi_encode:是一种abi.encodeWithSelectorhttps://ethereum.stackexchange.com/questions/132767
复制相似问题