I am trying to figure out how to send a transaction to a contract method, retrieve the transaction hash automatically, and then get a receipt callback after the transaction is mined.
I am able to do one or the other but seemingly not both. Any suggestions?
Contract.deployed().then(function(instance) {
instance.methodName(parameter, {from: this.account, value: price})
.then(function(receipt) {
//THIS FIRES AFTER THE TRANSACTION IS MINED,
//BUT I CANT GET THE TX HASH ANY SOONER
});
});
Contract.deployed().then(function(instance) {
instance.methodName.sendTransaction(parameter, {from: this.account, value: price})
.then(function(hash) {
//THIS FIRES BEFORE THE TRANSACTION IS MINED,
//BUT I NOW DON'T HAVE A WAY TO GET A MINED RECEIPT
});
});
instance.methodName()
andinstance.methodName.sendTransaction()
should perform identically in web3.js 0.2x.x, but I'm not sure about older versions, and I believe that pre-1.0.0 versions of web3.js don't support promises, so I believe you're dealing with some truffle magic instead. (Sorry, but I'm unfamiliar with truffle.)