I have a Smart Contract that represent ERC20 token. I already deployed the smart contract on Binance Testnet using HardHat.
I have a deployed Smart Contract address as well.
I have integrated Web3 library in PHP laravel project using following link.
https://github.com/web3p/web3.php
I can call web3 function to get TOKEN Symbol. It is working fine.
I want to transfer my tokens to some wallet address using 'transfer' function of the Smart contract.
I am using following code.
$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);
}
});
});
But I am getting following error.
{ "message": "Wrong type of eth_sendTransaction method argument 0.", "exception": "RuntimeException", "file": "/var/www/html/vendor/web3p/web3.php/src/Methods/EthMethod.php", "line": 125, "trace": [ { "file": "/var/www/html/vendor/web3p/web3.php/src/Eth.php", "line": 102, "function": "validate", "class": "Web3\\Methods\\EthMethod", "type": "->" }, { "file": "/var/www/html/vendor/web3p/web3.php/src/Contract.php", "line": 572, "function": "__call", "class": "Web3\\Eth", "type": "->" } ] }
Can someone please guide me on solving this?
Here is the Token.json -> ABI