Here is the function isDude
in a contract. If the address is recorded, then isDude
returns true. Otherwise it returns false. Here is the contract function isDude
:
function isDude(address _dude_address) external returns (bool) {
if (_dude_address == address(0)) return false;
if (!dudes[_dude_address]) emit dudeNotConfirmed(msg.sender, _dude_address);
return dudes[_dude_address]; //<<==return boolean
}
The dapp is using ethers 5.0.x
to call the function as below:
let dudeOnChain1 = await contractDude.isDude(wallet.address); //<<==wallet.address is on chain and shall return true
let dudeOnChain = await dudeOnChain1.wait();
console.log("Dude on china : ", dudeOnChain);
let d2 = await contractDude.isDude("0x617F2E2fD72FD9D5503197092aC168c91465E7f2"); //<<==this address is not on chain and shall return false
let d21 = await d2.wait();
console.log("Is on chain d21: ", d21);
Here is the console output of return for wallet.address
which shall be true:
[Thu Dec 24 2020 23:56:14.725] LOG Dude on china : {"blockHash": "0x2658158ba56d6ae53fd042ad442330c3fe9e76a84b13ff70a068fbe79175cf68", "blockNumber": 106269, "byzantium": true, "confirmations": 2, "contractAddress": null, "cumulativeGasUsed": {"hex": "0x5c90", "type": "BigNumber"}, "events": [], "from": "0xF89b29Fb7D2a2Ecf56A4BA57f1680aa9d47BE538", "gasUsed": {"hex": "0x5c90", "type": "BigNumber"}, "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": 1, "to": "0x19B9F726278BCca713ef999E4810cbB1A2977A41", "transactionHash": "0x2c2ad792447450e50f0e52b457f8e92e10389e74a40bf2b1ef326ae6480fadc0", "transactionIndex": 0}
Here is the return false for address which is not on chain (event dudeNotConfirmed has been fired):
[Thu Dec 24 2020 23:56:16.586] LOG Is on chain d21: {"blockHash": "0x7081b4fec59c5c8d6cc97a881adf10b6c1c21ab762033f9039c815e2a4dde62e", "blockNumber": 106271, "byzantium": true, "confirmations": 1, "contractAddress": null, "cumulativeGasUsed": {"hex": "0x61d7", "type": "BigNumber"}, "events": [{"address": "0x19B9F726278BCca713ef999E4810cbB1A2977A41", "args": [Array], "blockHash": "0x7081b4fec59c5c8d6cc97a881adf10b6c1c21ab762033f9039c815e2a4dde62e", "blockNumber": 106271, "data": "0x000000000000000000000000f89b29fb7d2a2ecf56a4ba57f1680aa9d47be538000000000000000000000000617f2e2fd72fd9d5503197092ac168c91465e7f2", "decode": [Function anonymous], "event": "dudeNotConfirmed", "eventSignature": "dudeNotConfirmed(address,address)", "getBlock": [Function anonymous], "getTransaction": [Function anonymous], "getTransactionReceipt": [Function anonymous], "logIndex": 0, "removeListener": [Function anonymous], "topics": [Array], "transactionHash": "0x8f289cb0f4b77789d8c24adc81ad5d7243af3882e52cdb52d08e3e7ca9ed3fda", "transactionIndex": 0}], "from": "0xF89b29Fb7D2a2Ecf56A4BA57f1680aa9d47BE538", "gasUsed": {"hex": "0x61d7", "type": "BigNumber"}, "logs": [{"address": "0x19B9F726278BCca713ef999E4810cbB1A2977A41", "blockHash": "0x7081b4fec59c5c8d6cc97a881adf10b6c1c21ab762033f9039c815e2a4dde62e", "blockNumber": 106271, "data": "0x000000000000000000000000f89b29fb7d2a2ecf56a4ba57f1680aa9d47be538000000000000000000000000617f2e2fd72fd9d5503197092ac168c91465e7f2", "logIndex": 0, "topics": [Array], "transactionHash": "0x8f289cb0f4b77789d8c24adc81ad5d7243af3882e52cdb52d08e3e7ca9ed3fda", "transactionIndex": 0}], "logsBloom": "0x00000000000000000000000000000000000002000000000000000000000000000000000000000000040000000000000000000000000000000010000000000000000000000000008000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000", "status": 1, "to": "0x19B9F726278BCca713ef999E4810cbB1A2977A41", "transactionHash": "0x8f289cb0f4b77789d8c24adc81ad5d7243af3882e52cdb52d08e3e7ca9ed3fda", "transactionIndex": 0}
The 2 returns above are much more than just a boolean. How to extract the boolean return of the isDude
from the return object above?