I am using web3.php project in my Ethereum based project. A part of this project is sending ERC20 tokens, and in this regard, I need to estimate gas limit of transaction. For this purpose, I found the example below in the official documents of this project as below:
$contract->at($contractAddress)->estimateGas($functionName, $params, $callback);
and I changed it to my own code like this:
$gasLimit = 0;
$contract = new Contract($web3->provider, $contract_abi);
$contract->at($contract_address)->estimateGas('transfer', [
'to'=>'0xa96Ce4C161271C797d979017821A278e1481eAfA',
'value'=>1
], function ($err, $gas) use (&$gasLimit) {
if ($err !== null) {
echo $err->getMessage();
return false;
} else {
$gasLimit = $gas;
}
}
);
After running this code, I receive this error:
PHP Fatal error: Uncaught InvalidArgumentException: Please make sure you have put all function params and callback...
And I am not sure what are the required params in $params
as the sample which is mentioned in this project. I tried to put something using documents provided for estimateGas()
here.
May you help me please to solve this issue?
transfer
takes parametersto
andamount
only. Transaction parametersfrom
,gas
,gasPrice
andvalue
are passed separately (i.e., as part of the transaction, not as part of the function call).transfer
(along with your input to that function), and pass it in thedata
field of that object.from
in the code and received the same result after that in regard to your first comment. In regard to your 2nd comment, I have used the$contract_abi
which is given based on the token user want to use. Do you mean anything else? Sorry, I'm new in Ethereum contracts and its related issues...estimateGas('transfer', '0xa96Ce4C161271C797d979017821A278e1481eAfA', 1, [ 'from' => '0x1234143..', 'gas' => '0x200b20' ], function (...) { ... })
.