Closed ridx807 closed 1 year ago
You might have to account for bandwidth points. If not bandwidth left, you should let (I think) 0.1 TRX for fees.
You might have to account for bandwidth points. If not bandwidth left, you should let (I think) 0.1 TRX for fees.
Not working, i also test balance-1000000 (1 trx in sun) as amount of send, my balance is 100 when i send 99000000 as amount is working. I want create python script which can read balance and send all automatically
I think if t
You might have to account for bandwidth points. If not bandwidth left, you should let (I think) 0.1 TRX for fees.
I think if tronpy update fiture like tronweb fromSun and toSun is can be worked
Don't know if related, but when you send to an address that has not been activated, you might need to spend 1 extra trx.
Don't know if related, but when you send to an address that has not been activated, you might need to spend 1 extra trx.
Yes i know, but i dont know how to do that in tronpy when i send balance and left 1-5 trx in wallet is not working This my script
from tronpy import Tron from tronpy.keys import PrivateKey
client = Tron(network='nile') priv_key = PrivateKey(bytes.fromhex("x)) address = "TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3" balance = client.get_account_balance(address)
txn = ( client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", balance-5_000) .memo("test memo") .build() .sign(priv_key) ) print(txn.txid) print(txn.broadcast().wait())
Buf if i write spesific balance let says 100 its working perfectly
from tronpy import Tron from tronpy.keys import PrivateKey
client = Tron(network='nile') priv_key = PrivateKey(bytes.fromhex("x)) address = "TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3" balance = client.get_account_balance(address)
txn = ( client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 10000000) .memo("test memo") .build() .sign(priv_key) ) print(txn.txid) print(txn.broadcast().wait())
Here, check this code I use. Modify according to your needs.
This is all inside a class.
def transferBalance(self, receiver: str,
amount: float,
contract: Optional[str] = None,
sender: Optional[str] = TRON_HOT_WALLET_ADDRESS,
senderpk: Optional[str] = TRON_HOT_WALLET_PK) -> dict:
"""
Transfers balance to another address
params:
sender: str -> Sender address
senderpk: str -> Sender Private Key
receiver: str -> Receiver address (send to this address)
amount: float -> amount to send
contract: Optional[str] -> Contract to send, if none assume TRX
"""
private_key = PrivateKey(bytes.fromhex(senderpk))
if contract:
contract = self.client.get_contract(contract)
decimals = contract.functions.decimals()
txn = (
contract.functions.transfer(receiver, int(amount * pow(10, decimals)))
.with_owner(sender) # address of the private key
.fee_limit(10_000_000)
.build()
.sign(private_key)
)
return txn.broadcast()
else:
try:
txn = (
self.client.trx.transfer(sender, receiver, int(amount*pow(10, 6)))
.build()
.sign(private_key)
)
except Exception as e:
coms.error(f"Error sending TRX {e}")
return False
else:
return txn.broadcast()
Sorry for the delay in the answer.
In general sending all balance is a tedious task because it requires to know the fee you will spend with 100% accuracy beforehand
Ideally, you can use BitcartCC for this (only it provides the most reliable fee estimation function), i.e. set up bitcartcc daemon via https://docs.bitcartcc.com/deployment/ or manually:
git clone https://github.com/bitcartcc/bitcart
cd bitcart
pip install -r requirements/base.txt
pip install -r requirements/daemons/trx.txt
TRX_SERVER=https://rpc.ankr.com/http/tron python3 daemons/trx.py
Then using https://github.com/bitcartcc/bitcart-sdk or https://github.com/bitcartcc/bitcart/releases/tag/cli-1.1.0 or any other language, you can do stuff like this:
from bitcart import TRX
from decimal import Decimal
coin = TRX(xpub="yourprivatekey")
request_amount = Decimal(coin.balance()["confirmed"])
estimated_fee = Decimal(coin.server.get_default_fee(coin.server.payto(payout.destination, request_amount, unsigned=True))
request_amount -= estimated_fee
tx_hash = await coin.pay_to("address", request_amount)
how to send all balance of TRX? when i want send using balance as amout, that alwalys fail. balance = client.get_account_balance(address)