XDCweb3


NameXDCweb3 JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/Ziusz/XDCweb3.py
SummaryXDCweb3.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens using web3.py
upload_time2024-06-18 17:19:19
maintainerNone
docs_urlNone
authorZiusz
requires_pythonNone
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.
            # 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:

```bash
pip install XDCweb3
```

## Usage

### Initializing the XRC20 Object

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

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

#### Get Total Supply

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

#### Get Decimals

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

#### Get Symbol

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

#### Get Balance of an Address

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

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

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

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

```python
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](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/XDCweb3.py",
    "name": "XDCweb3",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "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/45/5b/6c78e8154dfe10bf62dad4109120ab328ae3146f78dd603f6b53d98e73f2/xdcweb3-1.0.3.tar.gz",
    "platform": null,
    "description": "# XDCweb3.py\r\n\r\nXDCweb3.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 XDCweb3.py using pip:\r\n\r\n```bash\r\npip install XDCweb3\r\n```\r\n\r\n## Usage\r\n\r\n### Initializing the XRC20 Object\r\n\r\n```python\r\nimport XDCweb3\r\n\r\n# Initialize XRC20 object with RPC URL\r\nrpc_url = 'https://rpc.xdcrpc.com'  # Replace with your RPC URL\r\nxrc20 = 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_addr = '0x...'  # Replace with the token contract address\r\nname = xrc20.name(token_addr)\r\nprint(f\"Token Name: {name}\")\r\n```\r\n\r\n#### Get Total Supply\r\n\r\n```python\r\ntoken_addr = '0x...'  # Replace with the token contract address\r\ntotal_supply = xrc20.total_supply(token_addr)\r\nprint(f\"Total Supply: {total_supply}\")\r\n```\r\n\r\n#### Get Decimals\r\n\r\n```python\r\ntoken_addr = '0x...'  # Replace with the token contract address\r\ndecimals = xrc20.decimals(token_addr)\r\nprint(f\"Decimals: {decimals}\")\r\n```\r\n\r\n#### Get Symbol\r\n\r\n```python\r\ntoken_addr = '0x...'  # Replace with the token contract address\r\nsymbol = xrc20.symbol(token_addr)\r\nprint(f\"Symbol: {symbol}\")\r\n```\r\n\r\n#### Get Balance of an Address\r\n\r\n```python\r\ntoken_addr = '0x...'  # Replace with the token contract address\r\nowner_address = '0x...'  # Replace with the address to check balance\r\nbalance = xrc20.balance_of(token_addr, 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\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_addr, 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\nowner_address = '0x...'  # Sender's address\r\nowner_private_key = '0x...'  # Sender's private key\r\nspender_address = '0x...'  # Address allowed to spend tokens\r\namount = 1  # Amount of tokens to approve\r\n\r\ntx_hash = xrc20.approve(token_addr, 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\nspender_address = '0x...'  # 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_addr, 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_addr, 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\nspender_address = '0x...'  # Spender's address\r\nreceiver_address = '0x...'  # Receiver's address\r\nspender_private_key = '0x...'  # Spender's private key\r\namount = 1  # Amount of tokens to transfer\r\n\r\ntx_hash = xrc20.transfer_from(token_addr, 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": "XDCweb3.py is a Python library for interacting with XDC (XinFin Digital Contract) tokens using web3.py",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/Ziusz/XDCweb3.py"
    },
    "split_keywords": [
        "xdc",
        "sdk",
        "web3.py",
        "smartcontract",
        "token",
        "xrc20",
        "xrc721",
        "xinfin",
        "digital",
        "contract",
        "web3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "455b6c78e8154dfe10bf62dad4109120ab328ae3146f78dd603f6b53d98e73f2",
                "md5": "230e7de74d510b5ba174d5c05cb15a34",
                "sha256": "3d2dbc52ac136cc409ab1a4852f18533e7febc2aeab39c93d0ed4ee4b501fad8"
            },
            "downloads": -1,
            "filename": "xdcweb3-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "230e7de74d510b5ba174d5c05cb15a34",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3018,
            "upload_time": "2024-06-18T17:19:19",
            "upload_time_iso_8601": "2024-06-18T17:19:19.168926Z",
            "url": "https://files.pythonhosted.org/packages/45/5b/6c78e8154dfe10bf62dad4109120ab328ae3146f78dd603f6b53d98e73f2/xdcweb3-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-18 17:19:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ziusz",
    "github_project": "XDCweb3.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "xdcweb3"
}
        
Elapsed time: 0.36779s