I am attempt to get an address using methods.call(). And it's something error.
JS
var rcAddr = "0x683d1602fa7252d49cda8ac414c1641a56e73d03";
var methodName = "Access Control";
var register = new web3.eth.Contract(rcAbi, rcAddr);
var accAddr = register.methods.getContractAddr(methodName).call({
from: "0x70f99451d9878055ca8986021ca78f6edb8f1720",
gas: 10000000
});
console.log(accAddr)
solidity
function getContractAddr(string memory _methodName) public view returns (address _scAddress){
bytes32 key = stringToBytes32(_methodName);
_scAddress = lookupTable[key].scAddress;
}
}
I think I can get a address from function, but it's wrong. So I use console.log(accAddr)
output the result.
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
It return something else. I'm confused. methods.myMethod.call
in document say
Returns
Promise returns Mixed: The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices:
So It should return the value but why not.
Promise
, which will resolve when the call completes. Depending on where you're running this code, you can probably useawait
, or you can call.then
on thePromise
. (If none of that makes sense to you, search for a tutorial on promises or async/await in JavaScript. This concept isn't specific to Ethereum/web3.js.)