xdc


Namexdc JSON
Version 1.0.4 PyPI version JSON
download
home_pagehttps://github.com/Ziusz/xdc.py
Summaryxdc.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens using web3.py
upload_time2024-06-19 00:33:37
maintainerNone
docs_urlNone
authorZiusz
requires_python<4,>=3.8
licenseMIT
keywords xdc sdk web3.py smartcontract token xrc20 xrc721 xinfin digital contract web3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
pip install xdc
```

## Usage

### Initializing the XRC20 Object

```python
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

```python
token_address = '0x...'  # Token's contract address
name = xrc20.name(token_address)
print(f"Token Name: {name}")
```

#### Get Total Supply

```python
token_address = '0x...'  # Token's contract address
total_supply = xrc20.total_supply(token_address)
print(f"Total Supply: {total_supply}")
```

#### Get Decimals

```python
token_address = '0x...'  # Token's contract address
decimals = xrc20.decimals(token_address)
print(f"Decimals: {decimals}")
```

#### Get Symbol

```python
token_address = '0x...'  # Token's contract address
symbol = xrc20.symbol(token_address)
print(f"Symbol: {symbol}")
```

#### Get Balance of an Address

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

- Built with [web3.py](https://web3py.readthedocs.io/en/stable/)
- Tested with [pytest](https://docs.pytest.org/en/stable/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Ziusz/xdc.py",
    "name": "xdc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.8",
    "maintainer_email": null,
    "keywords": "xdc sdk web3.py smartcontract token xrc20 xrc721 xinfin digital contract web3",
    "author": "Ziusz",
    "author_email": "ziusz@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/86/3c/32d8ff18467d1ee8b9115cd1088a50785e77d883ea1270aa813790fa8cb0/xdc-1.0.4.tar.gz",
    "platform": null,
    "description": "# xdc.py\r\n\r\nxdc.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens (XRC20 for now) using web3.py.\r\n\r\n## Installation\r\n\r\nYou can install xdc.py using pip:\r\n\r\n```bash\r\npip install xdc\r\n```\r\n\r\n## Usage\r\n\r\n### Initializing the XRC20 Object\r\n\r\n```python\r\nimport xdc\r\n\r\n# Initialize XRC20 object with RPC URL\r\nrpc_url = 'https://rpc.xdcrpc.com'  # Replace with your RPC URL\r\nxrc20 = xdc.XRC20(rpc_url)\r\n```\r\n\r\n### Getting Token Information\r\n\r\n#### Get Token Name\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nname = xrc20.name(token_address)\r\nprint(f\"Token Name: {name}\")\r\n```\r\n\r\n#### Get Total Supply\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\ntotal_supply = xrc20.total_supply(token_address)\r\nprint(f\"Total Supply: {total_supply}\")\r\n```\r\n\r\n#### Get Decimals\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\ndecimals = xrc20.decimals(token_address)\r\nprint(f\"Decimals: {decimals}\")\r\n```\r\n\r\n#### Get Symbol\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nsymbol = xrc20.symbol(token_address)\r\nprint(f\"Symbol: {symbol}\")\r\n```\r\n\r\n#### Get Balance of an Address\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nowner_address = '0x...'  # Address to which you want to check the balance\r\nbalance = xrc20.balance_of(token_address, owner_address)\r\nprint(f\"Balance of {owner_address}: {balance}\")\r\n```\r\n\r\n### Transferring XDC and Tokens\r\n\r\n#### Transfer XDC\r\n\r\n```python\r\nowner_address = '0x...'  # Sender's address\r\nowner_private_key = '0x...'  # Sender's private key\r\nreceiver_address = '0x...'  # Receiver's address\r\namount = 1  # Amount to transfer in XDC\r\n\r\ntx_hash = xrc20.transfer_xdc(owner_address, owner_private_key, receiver_address, amount)\r\nprint(f\"Transfer XDC Transaction Hash: {tx_hash}\")\r\n```\r\n\r\n#### Transfer Tokens\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nowner_address = '0x...'  # Sender's address\r\nowner_private_key = '0x...'  # Sender's private key\r\nreceiver_address = '0x...'  # Receiver's address\r\namount = 1  # Amount of tokens to transfer\r\n\r\ntx_hash = xrc20.transfer_token(token_address, owner_address, owner_private_key, receiver_address, amount)\r\nprint(f\"Transfer Token Transaction Hash: {tx_hash}\")\r\n```\r\n\r\n#### Approve Token Transfer\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nowner_address = '0x...'  # Sender's address (address that allows to spend tokens)\r\nowner_private_key = '0x...'  # Owner's private key\r\nspender_address = '0x...'  # Spender's address (address allowed to spend tokens)\r\namount = 1  # Amount of tokens to approve\r\n\r\ntx_hash = xrc20.approve(token_address, owner_address, owner_private_key, spender_address, amount)\r\nprint(f\"Approve Token Transfer Transaction Hash: {tx_hash}\")\r\n```\r\n\r\n#### Increase/Decrease Allowance\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nowner_address = '0x...'  # Owner's address (address that allows to spend tokens)\r\nowner_private_key = '0x...'  # Owner's private key\r\nspender_address = '0x...'  # Spender's address (address allowed to spend tokens)\r\namount = 1  # Amount of tokens to adjust allowance\r\n\r\n# Increase Allowance\r\ntx_hash_increase = xrc20.increase_allowance(token_address, owner_address, owner_private_key, spender_address, amount)\r\nprint(f\"Increase Allowance Transaction Hash: {tx_hash_increase}\")\r\n\r\n# Decrease Allowance\r\ntx_hash_decrease = xrc20.decrease_allowance(token_address, owner_address, owner_private_key, spender_address, amount)\r\nprint(f\"Decrease Allowance Transaction Hash: {tx_hash_decrease}\")\r\n```\r\n\r\n#### Transfer Tokens From\r\n\r\n```python\r\ntoken_address = '0x...'  # Token's contract address\r\nowner_address = '0x...'  # Owner's address (address that allows to spend tokens)\r\nspender_address = '0x...'  # Spender's address (address allowed to spend tokens)\r\nspender_private_key = '0x...'  # Spender's private key\r\nreceiver_address = '0x...'  # Receiver's address\r\namount = 1  # Amount of tokens to transfer\r\n\r\ntx_hash = xrc20.transfer_from(token_address, owner_address, spender_address, spender_private_key, receiver_address, amount)\r\nprint(f\"Transfer From Transaction Hash: {tx_hash}\")\r\n```\r\n\r\n## License\r\n\r\nThis library is licensed under the MIT License.\r\n\r\n## Acknowledgments\r\n\r\n- Built with [web3.py](https://web3py.readthedocs.io/en/stable/)\r\n- Tested with [pytest](https://docs.pytest.org/en/stable/)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "xdc.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens using web3.py",
    "version": "1.0.4",
    "project_urls": {
        "Homepage": "https://github.com/Ziusz/xdc.py"
    },
    "split_keywords": [
        "xdc",
        "sdk",
        "web3.py",
        "smartcontract",
        "token",
        "xrc20",
        "xrc721",
        "xinfin",
        "digital",
        "contract",
        "web3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "863c32d8ff18467d1ee8b9115cd1088a50785e77d883ea1270aa813790fa8cb0",
                "md5": "6795831094fe2ed69a9408bcbc8a628f",
                "sha256": "817e6d9f549800aa92871198b82a45255008a079489fb504e86e6f5d06987aaa"
            },
            "downloads": -1,
            "filename": "xdc-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "6795831094fe2ed69a9408bcbc8a628f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8",
            "size": 4795,
            "upload_time": "2024-06-19T00:33:37",
            "upload_time_iso_8601": "2024-06-19T00:33:37.066655Z",
            "url": "https://files.pythonhosted.org/packages/86/3c/32d8ff18467d1ee8b9115cd1088a50785e77d883ea1270aa813790fa8cb0/xdc-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-19 00:33:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ziusz",
    "github_project": "xdc.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "xdc"
}
        
Elapsed time: 0.23695s