-
-
Save emailnjv/a1a581a673d195deedc558967547d559 to your computer and use it in GitHub Desktop.
Solidity Method Callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using the callback | |
myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'}, function(error, transactionHash){ | |
... | |
}); | |
// using the promise | |
myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'}) | |
.then(function(receipt){ | |
// receipt can also be a new contract instance, when coming from a "contract.deploy({...}).send()" | |
}); | |
// using the event emitter | |
myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'}) | |
.on('transactionHash', function(hash){ | |
... | |
}) | |
.on('confirmation', function(confirmationNumber, receipt){ | |
... | |
}) | |
.on('receipt', function(receipt){ | |
// receipt example | |
console.log(receipt); | |
> { | |
"transactionHash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b", | |
"transactionIndex": 0, | |
"blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", | |
"blockNumber": 3, | |
"contractAddress": "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", | |
"cumulativeGasUsed": 314159, | |
"gasUsed": 30234, | |
"events": { | |
"MyEvent": { | |
returnValues: { | |
myIndexedParam: 20, | |
myOtherIndexedParam: '0x123456789...', | |
myNonIndexParam: 'My String' | |
}, | |
raw: { | |
data: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', | |
topics: ['0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385'] | |
}, | |
event: 'MyEvent', | |
signature: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', | |
logIndex: 0, | |
transactionIndex: 0, | |
transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', | |
blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', | |
blockNumber: 1234, | |
address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' | |
}, | |
"MyOtherEvent": { | |
... | |
}, | |
"MyMultipleEvent":[{...}, {...}] // If there are multiple of the same event, they will be in an array | |
} | |
} | |
}) | |
.on('error', console.error); // If there's an out of gas error the second parameter is the receipt. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment