Code Monkey home page Code Monkey logo

trc20-lib's Introduction

TRC20 Library

Small Python library to manage TRC20 wallet. Allows to send USDT, TRX, and swap USDT<->TRX

The main API for TRX-USDT rate is CoinGecko but as they made their API very limited to non-paid users, it's better to use some backup API (LiveCoinWatch for example).

Also, I hardly handle any errors in the library, so it is advisable to do it externally when using it.

Requirements

tronpy >= 0.4.0 (tested on 0.4.0)

loguru >= 0.7.2 (tested on 0.7.2)

TronGrid API key

LiveCoinWatch API key

Example usage

#import library
import tronLib

#I use loguru in my projects so its better for you to configure the logs path for the logger, or change loguru to something you like (in the tronLib file)
from loguru import logger

#Setup logger, you can use your path and max filesize
logger.add("LOGS_PATH", rotation="5 MB")

#Initialize client
my_wallet = tronLib.MyTron(LIVE_COIN_WATCH_API_KEY, TRON_GRID_API_KEY, WALLET_PRIVATE_KEY)

#Get TRX balance
my_trx_balance = my_wallet.get_trx_balance()
print(f'TRX balance: {my_balance}')

#Get USDT balance
my_usdt_balance = my_wallet.get_coin_balance(tronLib.Contract.USDT)
print(f'USDT balance: {my_balance}')

#Check the given address for validity
is_valid_address(SOME_TRC20_ADDRESS)

#Send TRX
tx_id, status, data = my_wallet.send_trx(RECIPIENT_ADDRESS, AMOUNT_TRX_TO_SEND)

#Send USDT (you can add another token contract address to the Contracts enum and use it to send another token)
tx_id, status, data = my_wallet.send_coin(tronLib.Contract.USDT, RECIPIENT_ADDRESS, AMOUNT_TRX_TO_SEND)

#Swap TRX to USDT via SunSwap contract
tx_id, status, data = my_wallet.trx_to_usdt(AMOUNT_TRX_TO_SWAP)

#Swap USDT to TRX via SunSwap contract
tx_id, status, data = my_wallet.usdt_to_trx(AMOUNT_USDT_TO_SWAP)

trc20-lib's People

Contributors

danijcom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.