admin管理员组文章数量:1314320
I'm trying to call a simple contract method that just returns a string of data. I've based my code on the example that can be found in the docs => /reference#methodcall
tronWeb.trx.getContract("TFWbGYFVjUMKrHALdU4MnFWNYY9Uc5W9SZ").then(async contract => {
console.log(contract);
let abi = contract.abi;
console.log(abi);
let c = await tronWeb.contract({
abi
});
let result = await c.getBadgeOwner('something is up').call();
console.log(result);
});
The difference with what can be found in the docs, is that I'm loading the abi from my loaded contract, instead of hard coding it like in the example.
The error I get is index.js:105 Uncaught (in promise) TypeError: e.forEach is not a function
which seems to refer to the abi somehow:
I'm trying to call a simple contract method that just returns a string of data. I've based my code on the example that can be found in the docs => https://developers.tronwork/reference#methodcall
tronWeb.trx.getContract("TFWbGYFVjUMKrHALdU4MnFWNYY9Uc5W9SZ").then(async contract => {
console.log(contract);
let abi = contract.abi;
console.log(abi);
let c = await tronWeb.contract({
abi
});
let result = await c.getBadgeOwner('something is up').call();
console.log(result);
});
The difference with what can be found in the docs, is that I'm loading the abi from my loaded contract, instead of hard coding it like in the example.
The error I get is index.js:105 Uncaught (in promise) TypeError: e.forEach is not a function
which seems to refer to the abi somehow:
3 Answers
Reset to default 6For anyone tripping over the same beginner mistake, here's how to solve it:
Use contract().at() instead of getContract()
let contract = await tronWeb
.contract()
.at("TFWbGYFVjUMKrHALdU4MnFWNYY9Uc5W9SZ")
After that, you can call your contract methods just fine
let currentValue = await contract.getBadgeOwner('something is up').call();
setTimeout(async () => {
this.myContractOb = await
this.tronWeb.contract(myContract).at(this.contractAddress);
},10000);
Using above code with myContract as ABI json object having same issue.
I was doing the same mistake before. This works for me
async function a (){
let contract = await tronWeb.contract().at("TFWbGYFVjUMKrHALdU4MnFWNYY9Uc5W9SZ")
//console.log(contract);
let currentValue = await contract.getBadgeOwner('something is up').call();
console.log(currentValue);
}
a()
本文标签: javascriptHow to call a contract method with tronwebStack Overflow
版权声明:本文标题:javascript - How to call a contract method with tron-web - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741898480a2403723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论