method.call()

使用 call 来执行 pureview 智能契约方法。这些方法不会修改区块链,也不会花费任何执行成本,也不会向网络广播。

用法

//示例 1
let contract = await tronWeb.contract.at('contractAddress'); 
let result = await contract.function_name(para1,para2,...).call();

//示例 2
let contract = await tronWeb.contract.at('contractAddress'); 
let result = await contract["function_name"](para1,para2,...).call();

参数类型
如果合约的ABI在链上,则无需传递参数
如果合约的ABI不在链上,则需传入{_isConstant: true}

返回值类型
Object

示例

//示例 1
async function triggercontract(){
   let instance = await tronWeb.contract().at('TBBp5VF2q73hfMUoyxr138Kx3kbsi6HQRS');
   let res = await instance.totalSupply().call();
   console.log(res);
}
triggercontract();

//示例 2
async function triggercontract(){
   let instance = await tronWeb.contract().at('TBBp5VF2q73hfMUoyxr138Kx3kbsi6HQRS');
   let res = await instance["totalSupply"]().call();
   console.log(res);
}
triggercontract();

//示例 3:合约ABI不在链上,则需手动录入ABI
async function triggercontract(){
   let instance = await tronWeb.contract().at('TBBp5VF2q73hfMUoyxr138Kx3kbsi6HQRS');
   instance.loadAbi([{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]);
     let res = await instance.totalSupply().call({_isConstant:true})
   console.log(res);
}
triggercontract();