Skip to main content
Version: 6.0.1 - 6.0.2

call()

Use call to execute a pure or view smart contract method. These methods do not modify the blockchain, do not cost anything to execute and are also not broadcasted to the network.

Usage

//Example 1
let abi = [...];
let contract = await tronWeb.contract(abi, 'contractAddress');
let result = await contract.function_name(param1,param2,...).call();

//Example 2
let abi = [...];
let contract = await tronWeb.contract(abi, 'contractAddress');
let result = await contract["function_name"](param1,param2,...).call();

Returns

Object

Example

//example 1
async function triggercontract(){
let abi = [...];
let instance = await tronWeb.contract(abi, 'contractAddress');
let res = await instance.totalSupply().call();
console.log(res);
}
triggercontract();

//example 2
async function triggercontract(){
let abi = [...];
let instance = await tronWeb.contract(abi, 'contractAddress');
let res = await instance["totalSupply"]().call();
console.log(res);
}
triggercontract();

//example 3:the ABI of the smart contract is not on-chain
async function triggercontract(){
let abi = [];
let instance = await tronWeb.contract(abi, 'contractAddress');
instance.loadAbi([{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]);
let res = await instance.name().call({_isConstant:true})
console.log(res);
}
triggercontract();