First off, take a look at the web3.js
documentation on Contract methods. Next, make sure that you're working with an instance of your contract (e.g. MyContract = web3.eth.contract(abiArray).at(deployedAddress)
). Assuming that's all set, it depends on whether your contract function is modifying state.
If you aren't modifying state, then the syntax described by @sfmiller940 ought to work fine: MyContract.getKidneyIds().then(function(ids){ //do your thing})
.
async
/await
might not be supported in your browser console, so try using the callback syntax instead.
If you are modifying state, then that's a different story. When you modify state, that has to be a transaction, so it isn't confirmed immediately -- no way to definitely get return values. The easiest way to get a return value from a transaction is to emit an event with the information you need -- that event and its arguments will be present in the logs
of your transaction receipt:
MyContract.stateModifyingFunction(arg1, arg2, function(err, txHash){
let txReceipt = web3.eth.getTransactionReceipt(txHash);
// txReceipt.logs contains an array of all events fired while calling your fxn
});
contract.getKidneyIds.call().then(function(id){whatever})
. It should be adaptable to useawait
.