Comments (7)
Sometimes if nonce
will be wrong, created TX built and broadcast successfully, but blockchain does not accept that.
A nonce will be considered wrong when:
- An address has too many transactions happening at the same time or has pending transactions
- The node that is used to retrieve information is not updated
For fetching the current nonce
, the code using the below code, you can rewrite your own transferFrom
function and provide the correct nonce
. (that may be saved in DB!)
public function transferFrom(string $spender, string $from, string $to, float $amount, string $gasLimit = 'default', string $gasPrice = 'default')
{
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildTransferFromData($from, $to, $amount);
$nonce = Number::toHex($this->getEth()->getTransactionCount($spender, 'pending')); //<--this line
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($gasPrice)
->gasLimit($gasLimit)
->data($data)
->amount(0)
->build()
;
}
from php-erc20.
hello, i try to get getTransactionCount()
, all get 1, $spender = '0xdac17f958d2ee523a2206206994597c13d831ec7';
$nonce = Number::toHex($this->getEth()->getTransactionCount($spender));// result 1
$nonce = Number::toHex($this->getEth()->getTransactionCount($spender, 'pending'));// result 1
Do I just need a random nonce value, such as 123456, or does the nonce have to be a value that can be obtained from a specified method?
Wallet A authorized wallet B, and the contract used at the time of authorization was 0xdac17f958d2ee523a2206206994597c13d831ec7
When getting the nonce, passed in is the A wallet address or the contract address 0xdac17f958d2ee523a2206206994597c13d831ec7 ?
$nonce = Number::toHex($this->getEth()->getTransactionCount($spender, 'pending'));
I don't know much about this, I'm trying to learn recently, please help
from php-erc20.
public function transferFrom(string $spender, string $from, string $to, float $amount, string $gasLimit = 'default', string $gasPrice = 'default')
$gasPrice
When this parameter is not passed in, this error will be prompted. If I pass in 700000, it can be executed correctly. Does this need to be set manually?
insufficient funds for gas * price + value
Is it because of this reason that the TX cannot be obtained by query?
from php-erc20.
This address 0xdac17f958d2ee523a2206206994597c13d831ec7
is USDT contract, its connot be used as spender.
Spender should be one of your wallets.
nonce
is a sequential number starting from zero.
nonce
for address with no transaction is zero, and for each transaction, this number increased.
from php-erc20.
public function transferFrom(string $spender, string $from, string $to, float $amount, string $gasLimit = 'default', string $gasPrice = 'default')
$gasPrice
When this parameter is not passed in, this error will be prompted. If I pass in 700000, it can be executed correctly. Does this need to be set manually?insufficient funds for gas * price + value
Is it because of this reason that the TX cannot be obtained by query?
In script $gasPrice
has a default value, but in some case (as your) need to be set manually.
from php-erc20.
Did your problem solve?
from php-erc20.
closed due to inactivity
from php-erc20.
Related Issues (15)
- Impossible to send approve without ETH for gas HOT 3
- CURL ERROR HOT 6
- Got the transaction HASH, but the transaction was not successful
- mb_substr(): Argument #2 ($start) must be of type int, float given HOT 6
- insufficient funds for gas * price + value HOT 5
- TX fee (XX ether) exceeds the configured cap (1.00 ether) HOT 7
- Always insufficient funds for gas * price + value HOT 6
- insufficient funds for gas * price + value HOT 3
- Error "execution reverted" HOT 6
- How to make a transfer without a specific token HOT 6
- How to handle gasPrice and Limits HOT 1
- Approve Token HOT 2
- I can't understand the parameters. HOT 3
- I Need ERC721 In Php
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-erc20.