xdc.py
xdc.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens (XRC20 for now) using web3.py.
Installation
You can install xdc.py using pip:
pip install xdc
Usage
Initializing the XRC20 Object
import xdc
# Initialize XRC20 object with RPC URL
rpc_url = 'https://rpc.xdcrpc.com' # Replace with your RPC URL
xrc20 = xdc.XRC20(rpc_url)
Getting Token Information
Get Token Name
token_address = '0x...' # Token's contract address
name = xrc20.name(token_address)
print(f"Token Name: {name}")
Get Total Supply
token_address = '0x...' # Token's contract address
total_supply = xrc20.total_supply(token_address)
print(f"Total Supply: {total_supply}")
Get Decimals
token_address = '0x...' # Token's contract address
decimals = xrc20.decimals(token_address)
print(f"Decimals: {decimals}")
Get Symbol
token_address = '0x...' # Token's contract address
symbol = xrc20.symbol(token_address)
print(f"Symbol: {symbol}")
Get Balance of an Address
token_address = '0x...' # Token's contract address
owner_address = '0x...' # Address to which you want to check the balance
balance = xrc20.balance_of(token_address, owner_address)
print(f"Balance of {owner_address}: {balance}")
Transferring XDC and Tokens
Transfer XDC
owner_address = '0x...' # Sender's address
owner_private_key = '0x...' # Sender's private key
receiver_address = '0x...' # Receiver's address
amount = 1 # Amount to transfer in XDC
tx_hash = xrc20.transfer_xdc(owner_address, owner_private_key, receiver_address, amount)
print(f"Transfer XDC Transaction Hash: {tx_hash}")
Transfer Tokens
token_address = '0x...' # Token's contract address
owner_address = '0x...' # Sender's address
owner_private_key = '0x...' # Sender's private key
receiver_address = '0x...' # Receiver's address
amount = 1 # Amount of tokens to transfer
tx_hash = xrc20.transfer_token(token_address, owner_address, owner_private_key, receiver_address, amount)
print(f"Transfer Token Transaction Hash: {tx_hash}")
Approve Token Transfer
token_address = '0x...' # Token's contract address
owner_address = '0x...' # Sender's address (address that allows to spend tokens)
owner_private_key = '0x...' # Owner's private key
spender_address = '0x...' # Spender's address (address allowed to spend tokens)
amount = 1 # Amount of tokens to approve
tx_hash = xrc20.approve(token_address, owner_address, owner_private_key, spender_address, amount)
print(f"Approve Token Transfer Transaction Hash: {tx_hash}")
Increase/Decrease Allowance
token_address = '0x...' # Token's contract address
owner_address = '0x...' # Owner's address (address that allows to spend tokens)
owner_private_key = '0x...' # Owner's private key
spender_address = '0x...' # Spender's address (address allowed to spend tokens)
amount = 1 # Amount of tokens to adjust allowance
# Increase Allowance
tx_hash_increase = xrc20.increase_allowance(token_address, owner_address, owner_private_key, spender_address, amount)
print(f"Increase Allowance Transaction Hash: {tx_hash_increase}")
# Decrease Allowance
tx_hash_decrease = xrc20.decrease_allowance(token_address, owner_address, owner_private_key, spender_address, amount)
print(f"Decrease Allowance Transaction Hash: {tx_hash_decrease}")
Transfer Tokens From
token_address = '0x...' # Token's contract address
owner_address = '0x...' # Owner's address (address that allows to spend tokens)
spender_address = '0x...' # Spender's address (address allowed to spend tokens)
spender_private_key = '0x...' # Spender's private key
receiver_address = '0x...' # Receiver's address
amount = 1 # Amount of tokens to transfer
tx_hash = xrc20.transfer_from(token_address, owner_address, spender_address, spender_private_key, receiver_address, amount)
print(f"Transfer From Transaction Hash: {tx_hash}")
License
This library is licensed under the MIT License.
Acknowledgments
Metadata
Release files for xdc 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xdc-1.0.4.tar.gz | 4.8 kB | Without provenance | Details for xdc-1.0.4.tar.gz |
Release files / xdc-1.0.4.tar.gz
| Download URL | xdc-1.0.4.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
817e6d9f549800aa92871198b82a45255008a079489fb504e86e6f5d06987aaa
|
|
BLAKE2b-256 checksum How to use checksums |
863c32d8ff18467d1ee8b9115cd1088a50785e77d883ea1270aa813790fa8cb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for xdc 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.