tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
440 stars 277 forks source link

get TypeError: contract.<name function> is not a function #387

Closed arian0da closed 1 year ago

arian0da commented 1 year ago

why get TypeError: contract.balances is not a function??

`const TronWeb = require('tronweb') const HttpProvider = TronWeb.providers.HttpProvider; const fullNode = new HttpProvider("https://api.shasta.trongrid.io"); const solidityNode = new HttpProvider("https://api.shasta.trongrid.io"); const eventServer = new HttpProvider("https://api.shasta.trongrid.io"); const privateKey = '409bc0b7-2393-419d-b5e8-8534cfdaa043'; const tronWeb = new TronWeb(fullNode,solidityNode,eventServer);

async function triggerSmartContract() { try { const trc20ContractAddress = 'TWEv92whv1kDW3JqgNn5HHVhbfbnfhmQxC';//contract address let abi = [{"entrys":[{"stateMutability":"Nonpayable","type":"Constructor"},{"inputs":[{"indexed":true,"name":"user","type":"address"},{"name":"amount","type":"uint256"}],"name":"Deposit","type":"Event"},{"inputs":[{"indexed":true,"name":"user","type":"address"},{"name":"amount","type":"uint256"}],"name":"Withdrawal","type":"Event"},{"inputs":[{"indexed":true,"name":"user","type":"address"},{"name":"amount","type":"uint256"}],"name":"WithdrawalApproval","type":"Event"},{"inputs":[{"indexed":true,"name":"user","type":"address"},{"name":"amount","type":"uint256"}],"name":"WithdrawalRejection","type":"Event"},{"inputs":[{"indexed":true,"name":"user","type":"address"},{"name":"amount","type":"uint256"}],"name":"WithdrawalRequest","type":"Event"},{"outputs":[{"type":"uint256"}],"name":"MAX_WITHDRAWAL_AMOUNT","stateMutability":"view","type":"function"},{"outputs":[{"type":"uint256"}],"name":"WITHDRAWAL_COOLDOWN","stateMutability":"view","type":"function"},{"inputs":[{"name":"user","type":"address"}],"name":"approveWithdrawal","stateMutability":"Nonpayable","type":"Function"},{"outputs":[{"type":"uint256"}],"inputs":[{"type":"address"}],"name":"balances","stateMutability":"view","type":"function"},{"name":"deposit","stateMutability":"Payable","type":"Function"},{"outputs":[{"type":"uint256"}],"name":"fee","stateMutability":"view","type":"function"},{"outputs":[{"type":"uint256"}],"inputs":[{"type":"address"}],"name":"lastWithdrawalTime","stateMutability":"view","type":"function"},{"outputs":[{"type":"address"}],"name":"owner","stateMutability":"view","type":"function"},{"name":"pause","stateMutability":"Nonpayable","type":"Function"},{"outputs":[{"type":"bool"}],"name":"paused","stateMutability":"view","type":"function"},{"inputs":[{"name":"user","type":"address"}],"name":"rejectWithdrawal","stateMutability":"Nonpayable","type":"Function"},{"inputs":[{"name":"amount","type":"uint256"}],"name":"requestWithdrawal","stateMutability":"Nonpayable","type":"Function"},{"name":"unpause","stateMutability":"Nonpayable","type":"Function"},{"inputs":[{"name":"amount","type":"uint256"}],"name":"withdraw","stateMutability":"Nonpayable","type":"Function"},{"outputs":[{"type":"uint256"}],"inputs":[{"type":"address"}],"name":"withdrawalRequests","stateMutability":"view","type":"function"}]}]; let contract = await tronWeb.contract(abi, trc20ContractAddress); let result = await contract.balances().call(); console.log(result); } catch(error) { console.error(error) } }

triggerSmartContract();`

start940315 commented 1 year ago

please trylet contract = await tronWeb.contract(abi[0].entrys, trc20ContractAddress);