This is the function I use to send a signed transaction using Infura to invoke a smart contrac function (see details for the params of the transaction).

    web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).on('receipt', receipt => {
            // Now it is known the transaction ID, so let's build the public Etherscan url where the transaction details can be viewed.
            const url = `https://ropsten.etherscan.io/tx/${receipt.transactionHash}`;
            log(`Note: please allow for 30 seconds before transaction appears on Etherscan`.yellow)
    }).catch((err) => {
        log(`error occurred: ${err})`.red);

I can see the transactions working fine on Etherscan (Ropsten). But I have no idea of to get back in NodeJS the results of the smart contract functions. For example, this functions should return a simple test string, but where I can fetch it in NodeJS?

These are the params that I use to prepare the transaction (using ethereum-tx.js).

    const txParams = {
        gasPrice: 100000,
        gasLimit: 3000000,
        contractAddress: process.env.SMART_CONTRACT_ADDRESS,
        to: process.env.SMART_CONTRACT_ADDRESS,
        data: functionAbi,
        from: web3.eth.defaultAccount,
        nonce: '0x' + nonce

And this is the function of the smart contract that I prepare in NodeJS:

const contractFunction = PrintProofOfWork.methods.printRequested(byte32gcodeHash);
const functionAbi = contractFunction.encodeABI();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.