Closed A2DNEW closed 4 months ago
You need to use tronweb.trx.multiSign to sign this transaction which will need both your privateKey and OTHER_ADDRESS's privateKey.
You need to use tronweb.trx.multiSign to sign this transaction which will need both your privateKey and OTHER_ADDRESS's privateKey.
So, What is the point of permission? If I access to OTHER_ADDRESS privatekey, I can delegateResource directly without multiSign
I have a website for sell/buy energy And users add permission to my address for sell/buy energy from/to these accounts So, nobody give me privatekey!
For example: I imported my account to Tronlink and without privatekey it can delegate my resources in multiSign section
If you have the permission to delegate other's resource to someone, please try this:
const tx = await tronWeb.transactionBuilder.delegateResource(amount, 'TO_ADDRESS', 'ENERGY', 'OTHER_ADDRESS_THAT_PERMISION_TO_ME', true, 3600);
const stx = await tron.tronWeb.trx.multiSign(tx, 'YOUR_PRIVATEKEY', PERMISSION_ID);
const result = await tronWeb.trx.broadcast(stx);
If you have the permission to delegate other's resource to someone, please try this:
const tx = await tronWeb.transactionBuilder.delegateResource(amount, 'TO_ADDRESS', 'ENERGY', 'OTHER_ADDRESS_THAT_PERMISION_TO_ME', true, 3600); const stx = await tron.tronWeb.trx.multiSign(tx, 'YOUR_PRIVATEKEY', PERMISSION_ID); const result = await tronWeb.trx.broadcast(stx);
Thank you for your help
How can I calcute amount?
For example, I want to send 32000 energy
How can I convert energy to sun (trx)?
trx.toSun(32000)
return 320000000 and this amount does not correct
Because after send 320000000 delegate, account received more than 40000 energy, not 32000
Note: if I use this formula everything is ok: 32000 * Math.pow(10, 6) / 13.72;
But why 13.72
?
energy = trx_amount * total_energy_limit / total_energy_weight
so
amount = energy * (total_energy_weight / total_energy_limit)
You can get total_energy_weight and total_energy_limit throughtronWeb.trx.getAccountResources()
Hi @start940315 @A2DNEW please guide me, I want to delegate resource from address A to B. how do i give permission to address A to do that?
gidkom
https://tronweb.network/docu/docs/6.0.0-beta.3/API%20List/transactionBuilder/delegateResource
Here is the doc of delegateResource
. Remember you need to freeze your balance using freezeBalanceV2
first.
gidkom
https://tronweb.network/docu/docs/6.0.0-beta.3/API%20List/transactionBuilder/delegateResource Here is the doc of
delegateResource
. Remember you need to freeze your balance usingfreezeBalanceV2
first.
thank you very much. I got it working
Hi One user add my address and add these permissions:
Vote, Claim Voting Rewards, TRX Stake (2.0), Delegate Resources, Reclaim Resources.
I use this code to send energy from that account to another account:await tronweb.transactionBuilder.delegateResource(100000, 'TO_ADDRESS', 'ENERGY', 'OTHER_ADDRESS_THAT_PERMISION_TO_ME', true, 3600);
But I get error:Private key does not match address in transaction
If I changeOTHER_ADDRESS_THAT_PERMISION_TO_ME
toMY_ADDRESS
i get this error:delegateBalance must be less than available FreezeEnergyV2 balance