Coder Social home page Coder Social logo

Comments (7)

lessmore92 avatar lessmore92 commented on July 20, 2024

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:

  1. An address has too many transactions happening at the same time or has pending transactions
  2. 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.

alan-1993 avatar alan-1993 commented on July 20, 2024

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.

alan-1993 avatar alan-1993 commented on July 20, 2024

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.

lessmore92 avatar lessmore92 commented on July 20, 2024

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.

lessmore92 avatar lessmore92 commented on July 20, 2024

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.

lessmore92 avatar lessmore92 commented on July 20, 2024

Did your problem solve?

from php-erc20.

lessmore92 avatar lessmore92 commented on July 20, 2024

closed due to inactivity

from php-erc20.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.