I am trying to send raw transaction data for a contract from a React frontend to a Node backend, sign it, then send it to the Ropsten network. However I am always getting the error "Error: Returned error: transaction underpriced" no matter what I set the gas too. Most of the answers I have found have been in relation to "replacement transaction underpriced" but that doesn't apply here. Any help would be appreciated. Here is my code so far:

Front End

const publicAddress = accounts[0];

const agraContract = new web3.eth.Contract(config.ABI, 'an address');

var requestEncodedABI = agraContract.methods.requestAGRA(publicAddress).encodeABI();
const nonce = await web3.eth.getTransactionCount('an address');

var rawRequestTx = {
    nonce: nonce,
    to: 'an address',
    gasPrice: web3.eth.gasPrice,
    gasLimit: web3.eth.getBlock('latest').gasLimit,
    data: requestEncodedABI,
    chainId: 3

fetch('/api/transactions/signtx', {
    body: JSON.stringify(rawRequestTx),
    headers: {
        'Content-Type': 'application/json',
    method: 'POST',
    .then((response) => response.json())
    .catch(err => console.log(err));

Here is the backend

let web3 = new Web3(new Web3.providers.HttpProvider(process.env.INFURA_API_KEY));

export const sign = (req: Request, res: Response, next: NextFunction) => {
    const rawTx = req.body;
    const common = new Common({ chain: Chain.Ropsten });
    var tx = Transaction.fromTxData(rawTx, { common });
    var privateKey = Buffer.from(process.env.ADMIN_PRIV_KEY, 'hex');
    const signedTx = tx.sign(privateKey);
    var serializedTx = signedTx.serialize();
    return web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
        .on('receipt', () => {


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.