🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

XDCweb3

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

XDCweb3

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

1.0.3
PyPI
Maintainers
1

XDCweb3.py

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

Installation

You can install XDCweb3.py using pip:

pip install XDCweb3

Usage

Initializing the XRC20 Object

import XDCweb3

# Initialize XRC20 object with RPC URL
rpc_url = 'https://rpc.xdcrpc.com'  # Replace with your RPC URL
xrc20 = XRC20(rpc_url)

Getting Token Information

Get Token Name

token_addr = '0x...'  # Replace with the token contract address
name = xrc20.name(token_addr)
print(f"Token Name: {name}")

Get Total Supply

token_addr = '0x...'  # Replace with the token contract address
total_supply = xrc20.total_supply(token_addr)
print(f"Total Supply: {total_supply}")

Get Decimals

token_addr = '0x...'  # Replace with the token contract address
decimals = xrc20.decimals(token_addr)
print(f"Decimals: {decimals}")

Get Symbol

token_addr = '0x...'  # Replace with the token contract address
symbol = xrc20.symbol(token_addr)
print(f"Symbol: {symbol}")

Get Balance of an Address

token_addr = '0x...'  # Replace with the token contract address
owner_address = '0x...'  # Replace with the address to check balance
balance = xrc20.balance_of(token_addr, 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

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_addr, owner_address, owner_private_key, receiver_address, amount)
print(f"Transfer Token Transaction Hash: {tx_hash}")

Approve Token Transfer

owner_address = '0x...'  # Sender's address
owner_private_key = '0x...'  # Sender's private key
spender_address = '0x...'  # Address allowed to spend tokens
amount = 1  # Amount of tokens to approve

tx_hash = xrc20.approve(token_addr, owner_address, owner_private_key, spender_address, amount)
print(f"Approve Token Transfer Transaction Hash: {tx_hash}")

Increase/Decrease Allowance

spender_address = '0x...'  # Address allowed to spend tokens
amount = 1  # Amount of tokens to adjust allowance

# Increase Allowance
tx_hash_increase = xrc20.increase_allowance(token_addr, 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_addr, owner_address, owner_private_key, spender_address, amount)
print(f"Decrease Allowance Transaction Hash: {tx_hash_decrease}")

Transfer Tokens From

spender_address = '0x...'  # Spender's address
receiver_address = '0x...'  # Receiver's address
spender_private_key = '0x...'  # Spender's private key
amount = 1  # Amount of tokens to transfer

tx_hash = xrc20.transfer_from(token_addr, 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

  • Built with web3.py
  • Tested with pytest

Keywords

xdc sdk web3.py smartcontract token xrc20 xrc721 xinfin digital contract web3

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts