PHP get estimate GAS using web3 php

819 views Asked by At

I have been stuck for a couple of days while sending money using web3 PHP. Everything is working fine, and others are getting transferred to address successfully. But I am having some issues while getting the estimated GAS. I can get the gas price successfully, but please help me get the estimateGas using PHP.

Here is what I tried.

$web3->eth->estimateGas([  'from' => $tempWalletPublic,
    'value' => dechex($totalBalance),
    'to' => $userPublicAddress,], function ($err, $result) {
    print_r($result);
});

Also, I tried the transaction (EthereumTx Transaction) as follows.

//create the signature for buy token
$buyTokenSign = $contract->at('my contract address')->getData('buyToken', 
    $userPublicAddress);
//estimate gas
$estimateGasTrans = new Web3pTransaction([
    'from' => $tempWalletPublic,
    'value' => dechex($totalBalance),
    'to' => $userPublicAddress,
    'gas' => dechex(21000),
    'nonce' => dechex($nonce),
    'data' => $buyTokenSign
]);
$rawTransaction = $estimateGasTrans->sign($tempWalletPrivate);
$web3->eth->estimateGas($rawTransaction, function ($err, $result) {
    print_r($result);
});

I also attempted removing some parameters, but I got an invalid parameter at argument 0 for method eth_estimateGas errors.

0

There are 0 answers