首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >web3 ERC20令牌函数调用

web3 ERC20令牌函数调用
EN

Stack Overflow用户
提问于 2022-04-07 04:42:24
回答 1查看 1.4K关注 0票数 0

我有一个表示ERC20令牌的智能契约。我已经使用HardHat在Binance上部署了智能契约。

我也有一个部署的智能契约地址。

我已经在integrated项目中使用以下链接集成了Web3库。

代码语言:javascript
复制
https://github.com/web3p/web3.php

我可以调用web3函数来获取令牌符号。它很好用。

我想使用智能契约的“传输”功能将我的令牌转移到某个钱包地址。

我正在使用以下代码。

代码语言:javascript
复制
$timeout = 30; // set this time accordingly by default it is 1 sec
$web3 = new Web3(new HttpProvider(new HttpRequestManager('https://data-seed-prebsc-1- s1.binance.org:8545', $timeout)));
$ContractMeta = json_decode(file_get_contents(base_path('public/web3/Token.json')));
$contract = new Contract($web3->provider, $ContractMeta->abi);
$toAccount = 'WALLET_ADDRESS_OF_RECEIVER';
$fromAccount = 'PRIVATE_KEY_OF_SENDER';

$contract->at("DEPLOYED_WALLET_ADDRESS")->send('transfer', $toAccount, 18, [
        'from' => $fromAccount,
        'value' => '1000',
        'gas' => '0x200b20',
        'gasPrice' => '20000000000'
    ], function ($err, $result) use ($contract, $fromAccount, $toAccount) {
        if ($err !== null) {
            throw $err;
        }
        if ($result) {
            echo "\nTransaction has made:) id: " . $result . "\n";
        }
        $transactionId = $result;

        $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use ($fromAccount, $toAccount) {
            if ($err !== null) {
                throw $err;
            }
            if ($transaction) {
                echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\nTransaction dump:\n";
                var_dump($transaction);
            }
        });
    });

但我会跟着错误走。

{“消息”:“错误类型的"/var/www/html/vendor/web3p/web3.php/src/Methods/EthMethod.php",方法参数0。”,“异常”:"RuntimeException",“RuntimeException”:“eth_sendTransaction”行: 125,“跟踪”:{“eth_sendTransaction”:"/var/www/html/vendor/web3p/web3.php/src/Eth.php",“行”:102,“函数”:“验证”,“类”:“Web3 3\Method\EthMethod”,"type":"->“},{ "file":-> "line":572,"__call","class":"Web3\Eth","type":"->“}

有人能帮我解决这个问题吗?

这是Token.json -> ABI

ABI

EN

回答 1

Stack Overflow用户

发布于 2022-04-07 05:52:18

此错误告诉您,您在契约响应中没有名称= transfer和type = function的对象。

应该是这样的:

代码语言:javascript
复制
   {
      "constant": false,
      "inputs": [
        {
          "name": "_to",
          "type": "address"
        },
        {
          "name": "_value",
          "type": "uint256"
        }
      ],
      "name": "transfer",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    }
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71776428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档