首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏Ethereum

    Foundry单元测试之vm.expectRevert

    你可以传递错误选择器或者错误数据(错误选择器是 Solidity 错误的前四个字节,通常通过 abi.encodeWithSelector 或 abi.encodeWithSignature 编码)。 捕获其他类型的 revert 错误你可以通过 abi.encodeWithSelector 或 abi.encodeWithSignature 编码捕获任何 Solidity 错误。 如果捕获的是 自定义错误,你需要使用 abi.encodeWithSelector 或 abi.encodeWithSignature 来构建错误的数据。5. vm.expectRevert("Custom error message");自定义错误:如果是 Solidity 0.8.x+ 引入的自定义错误,则需要使用 abi.encodeWithSelector 或 abi.encodeWithSignature

    33600编辑于 2025-01-10
  • 来自专栏信且诚心之动

    使用delegatecall扩充合约功能

    address newLogic) external { require(msg.sender == owner); currentLogic.delegatecall(abi.encodeWithSignature setModule(address newModule) external { require(msg.sender == owner); module.delegatecall(abi.encodeWithSignature dc.delegatecall_contract_address; (bool success, ) = _target.delegatecall( abi.encodeWithSignature 可以使用 abi.encodeWithSignature 将函数调用的签名和参数打包。 异常处理: 在 delegatecall 中,被调用的合约抛出的异常会传递到调用者合约。

    42540编辑于 2023-11-14
  • 来自专栏dapp系统开发

    币安链BSC众筹系统开发技术详细分析

    (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature

    1.1K40编辑于 2022-08-09
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 13 课:Solidity 低级调用 call/delegatecall/staticcall —— 直接和 EVM“对话”

    (address _callee, uint256 _v) external payable { (bool success, ) = _callee.call( abi.encodeWithSignature callee) external view returns (uint256) { (, bytes memory data) = _callee.staticcall( abi.encodeWithSignature delegateSetValue(address _logic, uint256 _v) external { (bool success, ) = _logic.delegatecall( abi.encodeWithSignature

    48910编辑于 2025-08-15
  • 来自专栏深入浅出区块链技术

    理解以太坊ABI - 应用程序二进制接口

    returns (bytes):计算参数的紧密打包编码 abi. encodeWithSelector(bytes4 selector, …) returns (bytes): 计算函数选择器和参数的ABI编码 abi.encodeWithSignature function abiEncode() public constant returns (bytes) { abi.encode(1); // 计算1的ABI编码 return abi.encodeWithSignature

    1.4K20发布于 2018-08-23
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 5 课:依赖与外部调用 —— 合约交互的风险与防护

    (bool success, bytes memory data) = counter.call( abi.encodeWithSignature("increment()"));require( staticcalldelegatecall 使用当前合约的存储,常用于库合约调用staticcall 是只读调用,无法修改状态(bool success, ) = lib.delegatecall(abi.encodeWithSignature function callUnsafe(address counter) public { (bool success, ) = counter.call( abi.encodeWithSignature testCallInvalidSignature() public { // 模拟 .call 调用不存在函数 (bool success, ) = address(counter).call( abi.encodeWithSignature

    54820编辑于 2025-08-01
  • 来自专栏dapp系统开发

    如何开发DAPP丨LP丨IDO预售代币智能合约系统开发流程详细及源码

    (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature (bool sent, ) = address(exampleExternalContract).call{ value: contractBalance }(abi.encodeWithSignature

    1.1K10编辑于 2022-08-04
  • 来自专栏深入浅出区块链技术

    撸一个预言机(Oracle)服务,真香!— 上篇

    ; 12 (bool success,) = callbackAddr.call.gas(CALLBACK_GAS)(abi.encodeWithSignature(callbackFUN, queryId ; 21 (bool success,) = callbackAddr.call.gas(CALLBACK_GAS)(abi.encodeWithSignature(callbackFUN, queryId

    1.2K20发布于 2020-06-21
  • 来自专栏code人生

    Solidity:合约调用方式

    // ... } } contract B { function bar(address _a) public { _a.delegatecall(abi.encodeWithSignature external { // ... } } contract B { function bar(address _a) public { _a.call(abi.encodeWithSignature

    59910编辑于 2024-05-29
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 47 课:DeFi 实战(11) -- 治理代币 & 激励机制(Tokenomics & Governance)

    calldatas = new bytes[](1); targets[0] = address(this); values[0] = 0; calldatas[0] = abi.encodeWithSignature calldatas = new bytes[](1); targets[0] = address(this); values[0] = 0; calldatas[0] = abi.encodeWithSignature calldatas = new bytes[](1); targets[0] = address(this); values[0] = 0; calldatas[0] = abi.encodeWithSignature 第一个操作:调用 mockAction targets[0] = address(this); values[0] = 0; calldatas[0] = abi.encodeWithSignature // 第二个操作:调用另一个函数 targets[1] = address(this); values[1] = 0; calldatas[1] = abi.encodeWithSignature

    44610编辑于 2025-10-18
  • 来自专栏code人生

    Solidity:call 和 delegatecall

    success, bytes memory data) = _addr.call{ value: msg.value, gas: 5000 }(abi.encodeWithSignature public payable { (bool success, bytes memory data) = _addr.call{value: msg.value}( abi.encodeWithSignature

    46410编辑于 2024-05-28
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 29 课:智能合约安全审计案例复盘 -- Parity Wallet Hack(2017)

    // proxy 调用 foo() 应该成功 (bool ok1, bytes memory res1) = address(proxy).call( abi.encodeWithSignature selfdestruct"); // 代理 delegatecall 再调用 foo() 应该失败 (bool ok2, ) = address(proxy).call(abi.encodeWithSignature

    42610编辑于 2025-09-07
  • 来自专栏深入浅出区块链技术

    最详细的解释EVM的函数选择原理

    event FunctionCalldata(bytes);//事件,相当于定义特殊的日志函数 bytes memory functionCallfata = abi.encodeWithSignature 我们使用abi.encodeWithSignature() 来获取所需格式的 calldata。emit 记录了我们的 calldata,用于测试。 0x6057361d000000000000000000000000000000000000000000000000000000000000000a 以上字节码就是abi.encodeWithSignature

    83720编辑于 2022-04-08
  • 来自专栏开发Notes

    [区块链]Solidity小白菜系列进阶(二)

    external { (bool success, bytes memory _data) = _test.call{value: 111, gas:5000}( abi.encodeWithSignature address _test,uint _num) external payable { //签名编码调用 // _test.delegatecall( // abi.encodeWithSignature

    38820编辑于 2024-12-27
  • 来自专栏后端开发从入门到入魔

    智能合约设计模式:讲解代理模式及其安全漏洞(已删除侵权内容版本)

    require(msg.sender == admin, "Only admin can call this function"); bytes memory callData = abi.encodeWithSignature proxyAdmin() internal view returns (address) { return Address.functionDelegateCall(address(proxy), abi.encodeWithSignature

    56010编辑于 2024-03-28
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 33 课:多签钱包(Multisig Wallet)-- 合约设计与实现

    function testExecuteERC20Transfer() public { // 构造 ERC20 转账数据 bytes memory data = abi.encodeWithSignature test_RevertIf_NotEnoughConfirmations_ExecuteERC20Transfer() public { // 构造 ERC20 转账数据 bytes memory data = abi.encodeWithSignature

    89210编辑于 2025-09-15
  • 来自专栏商业模式策划

    浅谈佛萨奇2.0波场链/币安链/马蹄链智能合约系统开发技术详细及源码部署

    , int256 value) public {//注意,method必须为方法签名格式,且方法签名的参数间不能有空格,例如"save(string,int256)" callee.call((abi.encodeWithSignature

    67620编辑于 2022-12-15
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 12 课:Solidity 函数选择器与 ABI 编码原理

    keccak256("transfer(address,uint256)")), to, amount ));abi.encodeWithSelector:手动指定函数选择器abi.encodeWithSignature

    44010编辑于 2025-08-14
  • 来自专栏Ethereum

    《纸上谈兵·solidity》第 34 课:多签钱包(Multisig Wallet)-- 上线

    A: 可以,通过构造 data = abi.encodeWithSignature("transfer(address,uint256)", to, amount) 并把 destination 指为

    41810编辑于 2025-09-16
  • 来自专栏Pseudoyu

    Solidity 智能合约开发 - 基础

    addr.call(abi.encodeWithSignature("transfer(address,uint256)", 0xSomeAddress, 123)) 上述代码 abi.encodeWithSignature contract, uint _num) public payable { (bool success, bytes memory data) = _contract.delegatecall( abi.encodeWithSignature

    1.2K20编辑于 2023-04-11
领券