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

Transaction Error: insufficient funds for intrinsic transaction cost #4922

Open
Soheilprs opened this issue Jan 21, 2025 · 4 comments
Open
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@Soheilprs
Copy link

Ethers Version

6.13.5

Search Terms

No response

Describe the Problem

Hey everyone, i have a function that i get an uuid, and a signature map with signer address and a already signed message and i should serialized the v,r,s and txRequest object and broadcast in to the network.
This is my code:

import { JsonRpcProvider, ethers, Wallet, Transaction } from 'ethers';
import { Address, ChainTransaction, ChainTransactionStatus, SendTransactionsReturn, uuid } from '../../type';
import { keccak256 } from 'ethers';
import { getNetwork } from '../config/network';

export async function sendTransactions(
    transaction: ChainTransaction,
    signatures_map: {
        [transaction_uuid: uuid]: {
            [address: Address]: string;
        };
    }
): Promise<string | undefined> {

    const txIdMap: SendTransactionsReturn = {};

    const currentNetwork = getNetwork();
    const provider = new JsonRpcProvider(currentNetwork.rpcUrl);

    const bigIntReplacer = (key: string, value: any) => (typeof value === 'bigint' ? value.toString() : value);

    try {
        const txData = typeof transaction.data === 'string' ? JSON.parse(transaction.data) : transaction.data;

        const expectedHash = keccak256(ethers.toUtf8Bytes(JSON.stringify(txData, bigIntReplacer)));

        if (transaction.rawdata !== expectedHash) {
            throw new Error(`Mismatch between rawdata hash and computed hash for tx: ${transaction.transaction_uuid}`);
        }

        if (txData.chainId == null) {
            const network = await provider.getNetwork();
            txData.chainId = network.chainId;
        }

        const signerAddress = transaction.signers?.[0];
        if (!signerAddress) {
            throw new Error(`No signerAddress found in transaction.signers: ${transaction.transaction_uuid}`);
        }

        const userSignature = signatures_map[transaction.transaction_uuid]?.[signerAddress];
        // const userSignature = signatures_map[transaction.transaction_uuid][signerAddress[0]];
        console.log('User Signature', userSignature);
        if (!userSignature) {
            throw new Error(`No signature provided for tx: ${transaction.transaction_uuid}, signer: ${signerAddress}`);
        }

        const { r, s, v } = ethers.Signature.from(userSignature);

        const resolvedTo = await Promise.resolve(txData.to);

        const txRequest: ethers.Transaction = Transaction.from({
            to: txData.to,
            value: txData.value ? ethers.toBigInt(txData.value) : undefined,
            gasLimit: txData.gasLimit ? ethers.toBigInt(txData.gasLimit) : undefined,
            gasPrice: txData.gasPrice ? ethers.toBigInt(txData.gasPrice) : undefined,
            nonce: txData.nonce ?? (await provider.getTransactionCount(signerAddress, 'pending')),
            chainId: txData.chainId,
            data: txData.data,
            signature: { r, s, v }
            // v,
            // r,
            // s
        });

        console.log('Constructed Transaction Request:');
        console.log({
            to: txRequest.to,
            value: txRequest.value?.toString(),
            gasLimit: txRequest.gasLimit?.toString(),
            gasPrice: txRequest.gasPrice?.toString(),
            nonce: txRequest.nonce,
            chainId: txRequest.chainId,
            data: txRequest.data,
            signature: txRequest.signature,
        });

        console.log('Constructed Transaction:', txRequest);
        console.log('Serialized Transaction:', txRequest.serialized);


        const serializedTransaction = txRequest.serialized;
        console.log('Serialized Transaction:', serializedTransaction);

        return serializedTransaction;
    } catch (err: any) {
        console.error('Transaction Error:', err.message);
    }
}

export async function getTxRequest(
    signedTxHex: string,
): Promise<SendTransactionsReturn> {
    const txIdMap: SendTransactionsReturn = {};

    const currentNetwork = getNetwork();
    const provider = new JsonRpcProvider(currentNetwork.rpcUrl);

    try {
        const txResponse = await provider.broadcastTransaction(signedTxHex);
        console.log('Transaction Response:', txResponse);
    } catch (error: any) {
        console.error('Transaction Error:', error.message);
    }


    return txIdMap;
}

but when i do it, i get this error in my terminal:

console.error
      Transaction Error: insufficient funds for intrinsic transaction cost (transaction="0x01f87083014a3481d1830f446b8252089451256f5459c1dde0c794818af42569030901a09888018ee610ab61800080c080a0dc6c77be254eb38820ae46bd8227733d2842bd62d7e157273e4594c625c9c89ca0043d088ea6b863c6b4061a63da4eb3be9c4402b8088efec68b6ef32bf5a93c5f", info={ "error": { "code": -32000, "message": "insufficient funds for gas * price + value: balance 0, tx cost 112280030631520510, overshot 112280030631520510" } }, code=INSUFFICIENT_FUNDS, version=6.13.5)

What is the reason of this error?

Code Snippet

Contract ABI

Errors

Environment

No response

Environment (Other)

No response

@Soheilprs Soheilprs added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Jan 21, 2025
@ricmoo
Copy link
Member

ricmoo commented Jan 23, 2025

Never communicate outside this GitHub org. We will never request you "open a ticket" in another system.

Also, never reveal any private data to anyone. Ever. I will never ask for private keys, mnemonics, etc. The above comments appear to be spam, likely malicious. They will be deleted.

@ricmoo
Copy link
Member

ricmoo commented Jan 23, 2025

The above error means the sending account has insufficient funds to send a transactions. Make sure you are sending from the account you expect.

@Soheilprs
Copy link
Author

@ricmoo Is this possibles that i got hacked when I opened this link?
I mean my system.

@ricmoo
Copy link
Member

ricmoo commented Jan 23, 2025

Just opening a link should not impact your system. The link is definitely spam. Do not engage with it.

I will be deleting any post which includes a link to spam.

@ethers-io ethers-io deleted a comment Jan 23, 2025
@ethers-io ethers-io deleted a comment Jan 23, 2025
@ethers-io ethers-io deleted a comment from Soheilprs Jan 23, 2025
@ethers-io ethers-io deleted a comment Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

3 participants
@ricmoo @Soheilprs and others