我有一个表示ERC20令牌的智能契约。我已经使用HardHat在Binance上部署了智能契约。
我也有一个部署的智能契约地址。
我已经在integrated项目中使用以下链接集成了Web3库。
https://github.com/web3p/web3.php我可以调用web3函数来获取令牌符号。它很好用。
我想使用智能契约的“传输”功能将我的令牌转移到某个钱包地址。
我正在使用以下代码。
$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

发布于 2022-04-07 05:52:18
此错误告诉您,您在契约响应中没有名称= transfer和type = function的对象。
应该是这样的:
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}https://stackoverflow.com/questions/71776428
复制相似问题