andelf / tronpy

TRON Python Client Library.
MIT License
204 stars 96 forks source link

How can I send usdt with tronpy please help #105

Closed afshinita closed 6 months ago

reza-khalafi commented 1 year ago
    async def send_trc20(self, private_key, sender_address, receiver_address, amount_as_usdt):
        try:
            provider = HTTPProvider(api_key=self.trongrid_api_key)
            client = Tron(provider=provider)
            contract = client.get_contract(CONFIG_MODEL.tron.trc20_contract_address)  # USDT contract address
            pv_key = PrivateKey(bytes.fromhex(private_key))
            amount = trx_to_sun(
                amount_as_usdt)  # Prepare real usdt(Tronpy needs USDT like this) LIKE SUN  -> * 1_000_000
            txn = (
                contract.functions.transfer(receiver_address, amount)
                .with_owner(sender_address)  # public address of the (private key)
                .fee_limit(trx_to_sun(self.estimate_fee()))
                .build()
                .sign(pv_key)
            )
            tx_id = txn.txid
            result = txn.broadcast().wait()
            return tx_id, result
        except Exception as e:
            print(e)
            return None, None
afshinita commented 1 year ago

self.trongrid_api_key ein chi hast error mide dadash

afshinita commented 1 year ago

CONFIG_MODEL has error trx_to_sun has error it is not defined

MrNaif2018 commented 6 months ago

The docs have enough of examples