Skip to content
/ xdc.py Public

xdc.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens using web3.py

License

Notifications You must be signed in to change notification settings

Ziusz/xdc.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

xdc.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens using web3.py

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages