Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient funds when sending a transaction #56

Closed
kielabokkie opened this issue Mar 22, 2018 · 3 comments
Closed

Insufficient funds when sending a transaction #56

kielabokkie opened this issue Mar 22, 2018 · 3 comments

Comments

@kielabokkie
Copy link

First of all, great work on this @sc0Vu! I know this is still bleeding edge at the moment but I encountered an issue that I hope you can help me out with. Below is a snippet from my proof of concept code to send transactions on the rinkeby testnet.

$web3 = new Web3(new HttpProvider(new HttpRequestManager(env('INFURA_URL'), 5.0)));
$eth = $web3->eth;

$eth->getBalance(env('WALLET_ADDRESS'), function ($err, $balance) {
    if ($err !== null) {
        $this->error($err->getMessage());
    }
    $this->comment(sprintf('Current balance: %s ETH', wei_to_ether($balance)));
});

$eth->gasPrice(function ($err, $gasPrice) {
    if ($err !== null) {
        $this->error($err->getMessage());
    }
    $this->gasPrice = $gasPrice;
    $this->comment(sprintf('Gas price: %s gwei', wei_to_gwei($gasPrice->toString())));
});

$eth->estimateGas(['from' => env('WALLET_ADDRESS')], function ($err, $gas) {
    if ($err !== null) {
        $this->error($err->getMessage());
    }
    $this->gasEstimate = $gas;
    $this->comment(sprintf('Gas limit: %s units', $gas->toString()));
});

$eth->getTransactionCount(env('WALLET_ADDRESS'), 'pending', function ($err, $nonce) use ($eth) {
    if ($err !== null) {
        $this->error($err->getMessage());
    }
    $this->comment(sprintf('Nonce: %s', $nonce));

    for ($i = 0; $i < count($this->recipients); $i++) {
        $this->info(
            sprintf(
                'Sending %s ETH to %s',
                $this->recipients[$i]['amount'],
                $this->recipients[$i]['address']
            )
        );

        // @todo: should use TransactionFormatter to do all hex conversion (when it works)
        $txParams = [
            'from' => env('WALLET_ADDRESS'),
            'to' => $this->recipients[$i]['address'],
            'value' => sprintf(decimal_to_hex(ether_to_wei($this->recipients[$i]['amount']))),
            'nonce' => sprintf(decimal_to_hex($nonce->toString() + $i)),
            'gasLimit' => decimal_to_hex($this->gasEstimate->toString()),
            'gasPrice' => decimal_to_hex($this->gasPrice->toString()),
            'chainId' => 4,
        ];

        $transaction = new Transaction($txParams);

        $signedTransaction = $transaction->sign(env('WALLET_PRIVATE_KEY'));

        // Send the transaction
        $eth->sendRawTransaction(sprintf('0x%s', $signedTransaction), function ($err, $tx) {
            if ($err !== null) {
                $this->error($err->getMessage());
            }
            $this->comment(sprintf('TX: %s', $tx));
        });
    }
});

Everything works flawlessly until sending the transaction, it comes back with the following error insufficient funds for gas * price + value. I'm sure that I have sufficient funds, as I have a very similar proof of concept using web3js that works fine. Below are the transaction parameters right before signing for both versions:

PHP

array:7 [
  "from" => "0x83ca28679f477Cd4710B72D11e47905A66dd6Dd4"
  "to" => "0xEFd7b1e4F28Dcd8000abb62974A77DB6a35618A6"
  "value" => "0x5af3107a4000"
  "nonce" => "0x89"
  "gasLimit" => "0xcf08"
  "gasPrice" => "0x3b9aca00"
  "chainId" => 4
]

Javascript

{ from: '0x83ca28679f477Cd4710B72D11e47905A66dd6Dd4',
  to: '0xEFd7b1e4F28Dcd8000abb62974A77DB6a35618A6',
  value: '0x5af3107a4000',
  nonce: '0x89',
  gasLimit: '0xcf08',
  gasPrice: '0x3b9aca00',
  chainId: 4 }

As you can see the parameters are identical so I'm a bit lost as to why the transaction doesn't get through. Any thoughts?

@sc0Vu
Copy link
Member

sc0Vu commented Mar 23, 2018

Hi @kielabokkie ,
Thanks for report this, I had test sendRawTransaction lots of times with ethereum-tx js library and ethereum-tx php library, tested with infura json rpc service.
Both got insufficient funds error, I still try to find what happend here.
I think it's tx library issue or api service issue, still try to find way to fix it.

@kielabokkie
Copy link
Author

@sc0Vu I got the "Insufficient funds" error today through the JS library when I passed the chain ID as a string instead of an integer. Not sure if it is related but thought I mention it 😉️

@realtebo
Copy link

@kielabokkie I am frustrated... I am not able to call a function mutating status passing params... could you write an exmplae, because you're able to do this, please?

@sc0Vu sc0Vu closed this as completed Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants