5 WEB3.php bytes[] abiencode 编码出来的结果是错误的,,

调用的是 这个包

composer require web3p/web3.php

PHP 代码是这样的

<?php
namespace   app\fun\public;
use         kornrunner\Keccak;
use         Web3\Utils;
use         Web3\Contracts\Ethabi;
use         Web3\Contracts\Types\Address;
use         Web3\Contracts\Types\Boolean;
use         Web3\Contracts\Types\Bytes;
use         Web3\Contracts\Types\DynamicBytes;
use         Web3\Contracts\Types\Integer;
use         Web3\Contracts\Types\Str;
use         Web3\Contracts\Types\Uinteger;
class      abi 
{
   public function a()
   {
      $this->abi = new Ethabi([
                 'address' => new Address,
                 'bool'  => new Boolean,
                 'bytes' => new Bytes,
                 'dynamicBytes'  => new DynamicBytes,
                 'int' => new Integer,
                 'string' => new Str,
                  'uint'  => new Uinteger
                  ]);

echo $this->abi->encodeParameters(['bytes[]'], [['0x06fdde03','0x95d89b41']]);
   }
}
?>

返回的结果是这样的

0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000004
06fdde0300000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000004
95d89b4100000000000000000000000000000000000000000000000000000000

在 abi.hashex.org 调试返回的结果 这个结果是真确,,

0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000040
0000000000000000000000000000000000000000000000000000000000000080
0000000000000000000000000000000000000000000000000000000000000004
06fdde0300000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000004
95d89b4100000000000000000000000000000000000000000000000000000000

搞不懂 为什么。。。。。

请先 登录 后评论

最佳答案 2022-06-02 19:14

问题已经修复, 参看这个php文件。 替换掉就行了。。 decode encode 都能用 https://github.com/dawnvi/web3.php/blob/master/src/Contracts/SolidityType.php

打赏地址 0xc34570Df9Df66370c5E794E1D46Eec1D59281d2c

请先 登录 后评论

其它 1 个回答

老兵 - 全干攻城狮
请先 登录 后评论