Ethereum Web3-稳定性-如何使用DelegateCall?

Ethereum Web3-稳定性-如何使用DelegateCall?,ethereum,solidity,smartcontracts,Ethereum,Solidity,Smartcontracts,我正在努力学习如何使用坚实的delegatecall特性。我已从其他智能合约复制了以下delegatecall代码 function exec(address _to, bytes memory _data) internal returns (bytes memory result) { assembly { let succeeded := delegatecall( sub

我正在努力学习如何使用坚实的
delegatecall
特性。我已从其他智能合约复制了以下
delegatecall
代码

   function exec(address _to, bytes memory _data)
        internal
        returns (bytes memory result)
    {
        assembly {
            let succeeded := delegatecall(
                sub(gas, 5000),
                _to,
                add(_data, 0x20),
                mload(_data),
                0,
                0
            )
            let size := returndatasize

            result := mload(0x40)
            mstore(
                0x40,
                add(result, and(add(add(size, 0x20), 0x1f), not(0x1f)))
            )
            mstore(result, size)
            returndatacopy(add(result, 0x20), 0, size)

            switch iszero(succeeded)
                case 1 {
                    revert(add(result, 0x20), size)
                }
        }
    }
我已经创建了一个ERC20令牌,比如说
TokenABC
。然后,我创建智能合约,其中包含上述
delegatecall
函数。我们将其称为
delegateContract
。现在,我正在尝试执行
delegateContract
中的
delegatecall
,以便调用
TokenABC
中的
transfer
函数,将一些令牌转移到
收件人
地址

下面是我正在使用的web3代码。我只是尝试从ERC20令牌执行传递函数。我想我犯了一个非常简单的基本错误。我无法弄清楚它是什么,也无法修复它

        var data = web3.eth.abi.encodeFunctionCall({
            name: 'transfer',
            type: 'function',
            inputs: [{
                type: 'address',
                name: 'recipient'
            },{
                type: 'uint256',
                name: 'amount'
            }]
        }, ['<recipient address>', '10000000000000000000']);


        let tokenAddress = '<address of TokenABC>';

        const tx = delegateContract.methods.exec(
                    tokenAddress,
                    data
        );
我的最终目标是通过像上面的示例一样传递数据,从1inch或uniswap执行交换函数

谁能指导我如何做到这一点

多谢各位。 哈里什

Warning! Error encountered during contract execution [Reverted]