menu

Questions & Answers

Handle client's ethereum transaction through node backend

I want to log a user's ethereum transaction along with other meta into a database only if the transaction was successful. An example would be they successfully staked an nft on the clientside and signed it with their metamask

if (txSuccessful) fetch('/someApiToLogDataOfTx', {

But I want to do it without having to expose the api, so that means the entire tx would have to be processed through a backend that would essentially do the same?

With this idea, any tx would have to be signed before sending it to the api?

frontend

    var raw = '0x' + tx.serialize().toString('hex');
    web3.eth.sendRawTransaction(raw, function (err, transactionHash) {
      fetch('/someApiToLogDataOfTx', { raw } 
    });

backend

web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log) // some logging to db

Is this right? or is there some overthinking here?

Answers(1) :

Currently, it is not possible at least with Metamask, the most popular wallet provider. It does not let you just sign a transaction without broadcasting it. You can read about it more in this GitHub issue. Although many people were requesting this functionality, it has been rejected foremost because of the nonce handling issues that would arise.