We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to send BEP20 token but I get an error, here is my code:
function web3_send_token($from, $to, $amount, $contract_address, $private) { $web3 = new Web3('https://bsc-dataseed1.binance.org:443'); $web3->eth->gasPrice(function ($error, $gasPrice) use (&$result) { if($error) { $result = [ 'error' => 'Ошибка получения gasPrice: ' . $error->getMessage() ]; return; } $result['gasPrice'] = $gasPrice; }); $web3->eth->getTransactionCount($from, 'pending', function ($error, $nonce) use (&$result) { if($error) { $result = [ 'error' => 'Ошибка получения nonce: ' . $error->getMessage() ]; return; } $result['nonce'] = $nonce; }); $abi = '[{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]'; $contract = new Contract($web3->provider, $abi); $amount = bcmul($amount, bcpow('10', 18), 0); $contract->at($contract_address)->estimateGas('transfer', $to, $amount, ['from' => $from], function ($error, $gas) use (&$result) { if($error) { $result = [ 'error' => 'Ошибка оценки газа: ' . $error->getMessage() ]; return; } $result['gas'] = $gas; }); $data = $contract->at($contract_address)->getData('transfer', $to, $amount); $transaction = new Transaction([ 'to' => $contract_address, 'value' => '0x0', 'gasPrice' => '0x' . dec_hex($result['gasPrice']->toString()), 'gas' => '0x' . dec_hex($result['gas']->toString()), 'nonce' => '0x' . dec_hex($result['nonce']->toString()), 'data' => $data, 'chainId' => 56 ]); $signedTransaction = '0x' . $transaction->sign($private); $web3->eth->sendRawTransaction($signedTransaction, function ($error, $txid) use (&$result) { if($error) { $result = [ 'error' => 'Ошибка отправки транзакции: ' . $error->getMessage() ]; return; } $result = [ 'txid' => $txid ]; }); return $result; }
Result of execution:
Status: Fail https://bscscan.com/tx/0x4c127113b9cc15a5e6eec4f8522b758813474e51c0ec2746d199d71a6f8ae96e
What's wrong?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I want to send BEP20 token but I get an error, here is my code:
Result of execution:
Status: Fail
https://bscscan.com/tx/0x4c127113b9cc15a5e6eec4f8522b758813474e51c0ec2746d199d71a6f8ae96e
What's wrong?
The text was updated successfully, but these errors were encountered: