Closed fangao888 closed 2 years ago
Hi,
You can set custom parameters for gasPrice
and gasLimit
as 4th and 5th parameters.
Have a look at the approve
method definition:
approve(string $ownerAddress, string $spenderAddress, string $amount, string $gasLimit = 'default', string $gasPrice = 'default')
Did your problem solve?
$token = new USDT("https://mainnet.infura.io/v3/8038c7c7****");
$owner_address = '0x1d64720e43342bdd0E824e1dadEF'; $myapp_private = '0xbf15a4a052a3b59c1a55988e8a1e35056fbfacf94ce'; $myapp_address = '0x907Dc5716029B907BfFB223f0A'; $to_address = '0x907Dc5716029B907BfFB2';
$transfer_tx = $token->transferFrom($myapp_address, $owner_address, $to_address, 1); $transfer_tx_id = $transfer_tx->sign($myapp_private)->send();
How to solve this please?
Uncaught RuntimeException: insufficient funds for gas * price + value
insufficient funds for gas * price + value
This error usually happens, when the gas price and gas limit parameters value are wrong; in this library, there is a default value for those, But based on time and network (ETH network) gas price needs to be adjusted. Also gas limit is different for various methods.
You can search and learn more about gas price and gas limit, then in all methods of this library, you can set the correct value for these.
hi ,
// transferFrom
public function transferFrom(string $spender, string $from, string $to, string $amount, string $gasLimit = 'default', string $gasPrice = 'default',string $nonce = '')
{
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildTransferFromData($from, $to, $amount);
if(empty($nonce)){
$nonce = Number::toHex($this->getEth()
->getTransactionCount($spender, 'pending'));
}
if (strtolower($gasLimit) === 'default')
{
$gasLimit = $this->getGasLimit('transferFrom');
}
if (strtolower($gasPrice) === 'default')
{
$gasPrice = $this->getSafeGasPrice();
}
return (new TransactionBuilder())
->setEth($this->getEth())
->to($this->contractAddress)
->nonce($nonce)
->gasPrice("200000000000")
->gasLimit("100000")
->data($data)
->amount(0)
->build()
;
}
i have setting gasPrice、gasLimit like that, but it cant work . The responce is : { "jsonrpc": "2.0", "id": 724889050, "error": { "code": -32000, "message": "insufficient funds for gas * price + value" } }
please , how to fix it ? thanks
@jucci1887 Does the spender
wallet have enough balance to pay the transaction fee?
$owner_private = '0x922b775cef0410717c28e0b04c23ffa5a0e2*********';
$owner_address = '0x9118cc4212dCC83dca639de28FC0D47AfdE4C45F';
$token = new Token("0xdac17f958d2ee523a2206206994597c13d831ec7","https://mainnet.infura.io/v3/d5cd9b58d5ca43409486******");
//by this method we allow $myapp_address to send upto 99999 token behalf of $owner_address
$approve_tx = $token->approve($owner_address, "0x4E0E4CbdfBaB08e65F5ECAb25bEAA*******", 9999);
$approve_tx_id = $approve_tx->sign($owner_private)->send();
Hello author, I have a problem! It keeps prompting insufficient funds for gas But there is enough ETH in the account can you help me