0

I want to do a transaction from my website to a private blockchain and inform the user after the transaction is done. This is my code so far:

const web3 = new Web3(new Web3.providers.HttpProvider("http://<ip>:8545"));

// It's simple contract with just two functions (setA(string), getA()).
const A = web3.eth.contract("<abi>");
const contractInstance = A.at('<contractAddress>');

console.log("Call: " + contractInstance.getA()); // this is working

contractInstance.setA(
    "someStringValue",
    {from: web3.eth.coinbase},
    (error, result) => {
        if(!error) {
            console.log(result); // this is working, I get a TX string from here

            // I got this from the documentation.
            // here I'm note sure if this is the right way to do it....
            web3.eth.getTransactionReceipt(result, (error2, result2) => {
                if(!error2)
                     console.log(result2); // this is not working
                else
                    console.error(error2);
            });

        } else {
            console.error(error);
        }
    }
);

Calling my contract is working fine, and sending the transaction is working as well. The only missing part is setting a callback to notify the user after the transaction is written into a block. Can someone tell me how to do it?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.