Closed mbsaberi closed 2 years ago
@sc0Vu could you help me please?
+1
After a whole day of trying to figure this out I found the solution (hopefully this helps someone out)
In the readme it states you use this for gas estimation:
$contract->at($contractAddress)->estimateGas($functionName, $params, $callback);
What we (atleast I) assume that $params is an array to provide, in which it's not
The correct way to use this function is the following
$contract->at($contract_address)->estimateGas('transfer', $to_addr, the_number_of_tokens_to_send, ['from' => $from_addr], function($err, $resp) use (&$gas){
if($err){
Log::info("estimate gas error: ".$err->getMessage());
}
$gas = $resp->toString();
});
Which results in:
Since I'm using infura as my provider (they don't let you unlock wallets etc), you would just need to use Web3p/ethereum-tx to sign with a private key and send..
Again, I really hope someone doesn't have to spend as much time on this now
Cheers
Addition to that, for contract calls that doesn't have any input parameters, such as enableTransfers, you can use that;
$contract->at($contractAddress)->estimateGas('enableTransfers',['from' => $fromAddr],function($err,$result) use($contract) {
if ($err !== null) {
throw $err;
}
if ($result) {
var_dump($result);
}
});
Which results in:
{
["value"]=>
string(8) "0x018d16"
["engine"]=>
string(16) "bcmath (OpenSSL)"
}
Thanks @conorwatt1 for adding the ['from' => $fromAddr]
part.
@mbsaberi
how fix this problem?
Thanks for your reply (@conorwatt1 @nithronium )!
Basically, the function parameter of estimate gas are: functionName
, paramsToSmartContract(leave empty)...
and transactionObject
.
Take erc20 transfer as example:
estimateGas('transfer', $toAccount, $amount, [
'from' => $fromAccount,
]
You can find example here: https://github.com/web3p/examples
Hi. I've used the provided samples and something I have found in other issues to estimate the
transfer
function of contracts like below, but I receive errors after executing the code: My Code:Error:
What is the
$params
parameter in theestimateGas
method exactly?