Closed LACT17 closed 2 months ago
I guess you are using tronweb beta version which is written using typescript. It's a compilation problem. You have to define a proper type for the contract you are going to call. Or you want to save time, just add an // @ts-ignore
before the code line.
I'm trying to follow the tronWeb documentation (https://tronweb.network/docu/docs/6.0.0-beta.1/Interact%20with%20contract#call) to retrieve the USDT balance from a wallet address. However, I'm encountering an error message: "Property 'balanceOf' does not exist on type 'Contract'." This is the code:
let abi = [
{
'outputs': [{ 'type': 'uint256' }],
'constant': true,
'inputs': [{ 'name': 'who', 'type': 'address' }],
'name': 'balanceOf',
'stateMutability': 'View',
'type': 'Function'
},
{
'outputs': [{ 'type': 'bool' }],
'inputs': [
{ 'name': '_to', 'type': 'address' },
{ 'name': '_value', 'type': 'uint256' }
],
'name': 'transfer',
'stateMutability': 'Nonpayable',
'type': 'Function'
}
];
let contract = await tronWeb.contract(abi, 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');
let result = await contract.balanceOf('TKbfAqmG1UFRiBFSXCtk4PXFgqkaxJ1SSy').call();
console.log(result.toString(10));
Can you help by giving me an example?, please.
try this:
let abi = [
{
'outputs': [{ 'type': 'uint256' }],
'constant': true,
'inputs': [{ 'name': 'who', 'type': 'address' }],
'name': 'balanceOf',
'stateMutability': 'View',
'type': 'Function'
},
{
'outputs': [{ 'type': 'bool' }],
'inputs': [
{ 'name': '_to', 'type': 'address' },
{ 'name': '_value', 'type': 'uint256' }
],
'name': 'transfer',
'stateMutability': 'Nonpayable',
'type': 'Function'
}
];
let contract = await tronWeb.contract(abi, 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');
// @ts-ignore
let result = await contract.balanceOf('TKbfAqmG1UFRiBFSXCtk4PXFgqkaxJ1SSy').call();
console.log(result.toString(10));
I tried with the // @ts-ignore and I get an error of "Property 'balanceOf' does not exist on type 'any[]'.". Can you help me with an example ?, please.
Please upload this screenshot of the error. So we can locate the problem.
I'm encountering an issue retrieving the USDT (TRC20 token) balance. I've followed the steps outlined in the TronWeb documentation for calling contracts (https://tronweb.network/docu/docs/6.0.0-beta.0/Interact%20with%20contract#call), but I'm getting an error message stating "Property 'balanceOf' does not exist on type 'Contract'." This functionality previously worked with TronWeb version prior to 6.0, but no longer functions with the current version.