1

I'm using web3 1.0 beta, and I'd like to get TxId before it's mine

I find a lot answer with sendTransaction, but If I use it I get sendTransaction is not a function

My code is like this:

c.istanza.methods.registraTicket(matricola).send({
   from: c.defaultAccount
}).then(
(valore) => {....},
(err) => {....})

In this way, from my client, I can call my function in my Smart contract. c.istanza is istanza = new web3.eth.Contract(data.abi, data.address);

If i Use something like this

c.istanza.methods.registraTicket(matricola).sendTransaction({
            from: c.defaultAccount
        }).then(
            (valore) => {

            },
            (err) => {
                console.dir(err);
            }
        )

I have a problem sendTransaction is not a function.

How can I get TxId before it mined? I want to have this id, because I store it in Database and I can check when it's mined (it's correct to check this ?)

thanks

2

The documentation for send is here: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-send.

It looks like you want the transactionHash event of the return value. The example from the documentation is as follows:

// using the event emitter
myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'})
.on('transactionHash', function(hash){
    ...
})

("Transaction hash" is I assume what you mean by "TxId".)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.