{'code': -32000, 'message': 'insufficient funds for gas * price + value'}

Hello!
I’m working on django, keep getting the error in title and really don’t know how to manage it

here’s the code:

from web3 import Web3

def sendTransaction(message):
    w3 = Web3(Web3.HTTPProvider('myendpoint'))
    address = 'myaddress'
    privateKey = 'myprivatekey'
    nonce = w3.eth.getTransactionCount(address)
    gasPrice = w3.eth.gasPrice
    value = w3.toWei(0, 'ether')
    signedTx = w3.eth.account.signTransaction(dict(
        nonce=nonce,
        gasPrice=gasPrice,
        gas= 100000,
        to='0x0000000000000000000000000000000000000000',
        value=value,
        data=message.encode('utf-8')
    ), privateKey)

    tx = w3.eth.sendRawTransaction(signedTx.rawTransaction)
    txId = w3.toHex(tx)
    return txId

can you help me please? <3

Hey @Aokami, and welcome to the Infura community!

Have you tried increasing the amount of gas you’re using?
Or perhaps you can update the chainId to be something other than 0 if you have the chainId in a different file.
Additionally, you can check to make sure you have 0x before your PK that comes from MetaMask :slight_smile:

Also, if you’re calling simple read-only calls elsewhere that may be depleting your gas, you can explicitly use a gasPrice of 0, as this thread mentions at the bottom.

It’s a lot of information, but hopefully one of these helps you out! Let us know what works for you (or if none of these work, and we’ll keep digging)!

1 Like