const Caver = require('caver-js')
const caver = new Caver('https://ennode.url.com/')
const abi = JSON.parse('[{"inputs" : [],"stateMutability" : "nonpayable","type" : "constructor"},....}]');
const contractAddress = '0xExample2E1f240b64e097FF0';
const contractInstance = new caver.contract(abi, contractAddress, { gasPrice: '25000000000' })
contractInstance.methods.totalSupply().call().then(console.log) <-이렇게 해도 안됩니다.
async function testGetContractValue() { <- 이렇게도 해봤습니다.
const contractInstance = new caver.contract(abi, contractAddress, { gasPrice: '25000000000' })
contractInstance.options.gas = 5000000
contractInstance.options.gasPrice = '25000000000000'
try {
const val = await contractInstance.methods['totalSupply()'].call();
//const value = await contractInstance.methods.decimals().call()
console.log(val.data)
}
catch (error) {
console.log("error: ", error.message)
}
}
아래와 같은 에러가 발생합니다.
(node:58001) UnhandledPromiseRejectionWarning: Error: Returned values aren't valid, did it run Out of Gas?
at ABICoder.decodeParameters (/User/caver-js/node_modules/caver-js/packages/caver-abi/src/index.js:256:15)
at Contract._decodeMethodReturn (/User/caver-js/node_modules/caver-js/packages/caver-contract/src/index.js:567:24)
at Method.outputFormatter (/User/caver-js/node_modules/caver-js/packages/caver-contract/src/index.js:997:42)
at _formatOutput (/User/caver-js/node_modules/caver-js/packages/caver-core-method/src/index.js:207:87)
at Method.formatOutput (/User/caver-js/node_modules/caver-js/packages/caver-core-method/src/index.js:211:60)
at /User/caver-js/node_modules/caver-js/packages/caver-core-method/src/index.js:240:25
at /User/caver-js/node_modules/caver-js/packages/caver-core-requestmanager/src/index.js:162:17
at XMLHttpRequest.request.onreadystatechange (/User//caver-js/node_modules/caver-js/packages/caver-core-requestmanager/caver-providers-http/src/index.js:119:13)
at XMLHttpRequestEventTarget.dispatchEvent (/User/caver-js/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/User/caver-js/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
(node:58001) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:58001) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.