Unable to broadcast this transaction to rinkeby with infura api

I have not been able to push to the rinkeby network using ether.js (or web3.js) and Infura.
My code looks somewhat like this. I will appreciate any help. Thanks.

API

router.post('/path', (req, res, next) => {
  let provider = new ethers.providers.InfuraProvider('rinkeby', '1234567...');
  let wallet = new ethers.Wallet(privateKey, provider);  
  let contract = new ethers.Contract(contractAddress, abi, wallet);  

   // Set a new Value, which returns the transaction
   let tx = await contract.setValue("I like turtles.");   
   console.log(tx.hash);
   0x1aee299e82442985d57c26b5dc480e4a9c095677efdfc67dd7be12b419569d26
   https://rinkeby.etherscan.io/tx/0x1aee299e82442985d57c26b5dc480e4a9c095677efdfc67dd7be12b419569d26

   await tx.wait();
   // [ Nothing happens after this point until the program timesout]
   // I have enough ether
   // Am using the correct wallet private key

   // Call the Contract's getValue() method again
   let newValue = await contract.getValue();   
   console.log({currentValue});

  await tx.wait();  

  
  res.json('done');
})

SMART CONTRACT
pragma solidity >=0.4.24 <0.7.0;

contract SimpleStore {

    event ValueChanged(address indexed author, string oldValue, string newValue);

    string _value;

    constructor(string memory value) public {
        emit ValueChanged(msg.sender, _value, value);
        _value = value;
    }

    function getValue() view public returns (string memory) {
        return _value;
    }

    function setValue(string memory value) public  {
        emit ValueChanged(msg.sender, _value, value);
        _value = value;
    }
}

Hi @_Sab, I recommend following this guide and modifying your code to be what’s shown here: https://medium.com/coinmonks/hello-world-smart-contract-using-ethers-js-e33b5bf50c19

1 Like

For any having a similar issue, I solved this by providing an override with the correct nonce (manually at first) and automated from

wallet.getTransactionCount(‘pending’).

Everything started acting properly from here on, including the web3.js implementation

1 Like