tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
423 stars 271 forks source link

calculate fee does not work #417

Closed m0x61h0x64i closed 1 year ago

m0x61h0x64i commented 1 year ago
const contractAddress = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
const { abi } = await tronWeb.trx.getContract(contractAddress)
const contract = await tronWeb.contract(abi.entrys, contractAddress)
const balance = await contract.methods.balanceOf('TEngJ8cwfWbGMcHRNEDqwzY9QGzY3HGd91').call()
const fee = await contract.methods.calcFee(10).call()
console.log(fee.toString())

this returns 0 but the actual fee of USDT is not 0, how can i use calcFee method ? they are no documents and no auto completions and issue or reference about this, please help

m0x61h0x64i commented 1 year ago

i cant even see the function to see how it works,

this console.log(contract.methods.calcFee.toString()) shows : function () { [native code] }

start940315 commented 1 year ago

see our documentation

m0x61h0x64i commented 1 year ago

@start940315 i got no results about calcFee function on the documentation, i want to calculate send USDT fee.

but when i want to send a transaction i can see its fee I have done this :

import TronWeb from 'tronweb'
const tronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
    privateKey: '981...........',
    headers: { 'TRON-PRO-API-KEY': process.env.TRON_PRO_API_KEY }
})
const functionSelector = 'transfer(address,uint256)';
const parameter = [{type:'address',value:'TEngJ8cwfWbGMcHRNEDqwzY9QGzY3HGd91'},{type:'uint256',value:100}]
const tx = await tronWeb.transactionBuilder.triggerSmartContract('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', functionSelector, {}, parameter);
const signedTx = await tronWeb.trx.sign(tx.transaction);
console.log(signedTx)

it shows an object which it has a raw_data property and raw_data has a fee_limit with value of 150000000, what does this value means ? whats my transaction fee now?

start940315 commented 1 year ago

fee_limit means the transaction must be finished under the fee_limit. You can know the fee consumed on tronscan.

m0x61h0x64i commented 1 year ago

Hi @start940315, thanks for your answer, i have checked https://tronscan.org/#/token20/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t but i cant see USDT fee, i tried to find it but i couldnt.

image

can you tell me where it is ?

start940315 commented 1 year ago

USDT transaction is a normal smart contract triggering. So you can use estimateEnergy function in transaction Builder