Skip to main content

Python SDK for Newrl blockchain

Project description

newrl

This library contains wrapper functions for interacting with the Newrl blockchain. Off chain and on chain operations are available.

Installation

Add newrl to your project requirements and/or run the installation with:

pip install newrl

Usage

Initialise a node connection

A node address along with port can be given to initialise a new node connection. If no address is provided, the default newrl foundation node at address http://newrl.net:8090 will be used.

node = Node('http://3.6.236.206:8090')

Off chain operations

Get file hash

Certain Newrl operations use document hashes for verification purpose. A file hash can be obtained with the below command.

from newrl import get_file_hash

file_hash = get_file_hash('/Users/admin/Documents/Tokenisation_Agreement1.pdf')
print(file_hash)

Generate new wallet

A wallet address generation can be done off-chain. The result is a dictionary containing public, private and address of the new wallet. A wallet once generated should be added to the chain to make it available for use.

from newrl import generate_wallet_address

wallet = generate_wallet_address()

Sign transaction

A transaction need to be signed with the applicable wallet for addition to chain.

from newrl import sign_transaction

signed_wallet_add_transaction = sign_transaction(wallet, wallet_add_transaction)
print(signed_wallet_add_transaction)

On chain operations

Add wallet to chain

A wallet address once genearated need to be signed and then added to the chain.

def add_wallet(
    custodian_address: str,
    jurisdiction: str,
    public_key: str,
    ownertype: str = '1',
    kyc_docs: list = [],
    specific_data: dict = {},
)

Example

wallet_add_transaction = node.add_wallet(
    wallet['address'], '910', wallet['public'], 1)

print(wallet_add_transaction)

Add token to chain

A token can be created, signed and then validated to add to the chain.

def add_token(
        token_name: str,
        token_type: str,
        first_owner: str,
        custodian: str,
        legal_doc_hash: str,
        amount_created: int,
        value_created: int,
        disallowed_regions: list = [],
        token_attributes: dict = {},
        is_smart_contract_token: bool = False,
    )

Example

    token_add_transaction = node.add_token(
        'my_new_token',
        '1',
        '0x16031ef543619a8569f0d7c3e73feb66114bf6a0',
        '0x16031ef543619a8569f0d7c3e73feb66114bf6a0',
        'fhdkfhldkhf',
        10000,
        10000,
    )

Add transfer

A transfer can be created between two wallets either unilaterally or bilaterally depending on the transfer type.

def add_transfer(
        self,
        asset1_code: int,
        asset2_code: int,
        wallet1_address: str,
        wallet2_address: str,
        asset1_qty: int,
        asset2_qty: int,
        transfer_type: int = 4,
    )

Example

    transfer_transaction = node.add_transfer(
        9, 10, '0x16031ef543619a8569f0d7c3e73feb66114bf6a0', '0x16031ef543619a8569f0d7c3e73feb66114bf6a0', 10, 10, 4)
    signed_transfer = sign_transaction(wallet, transfer_transaction)
    print(signed_transfer)

Get balance

The balance of a given token in a wallet, across wallets or all tokens in a wallet can be obtained with get balance function.

    node.get_balance(balance_type, wallet_address, token_code)

Example

    node.get_balance('TOKEN_IN_WALLET', '0xc29193dbab0fe018d878e258c93064f01210ec1a', 9)

Validate transaction

A singed transaction need to be validated to be added to the chain.

    validate_result = node.validate_transaction(signed_transfer)
    print(validate_result)

Run updater

Run the miner to create a new block out of the transactions. If no valid transactions are found then an empty block will be created. This operation is not meant to be called and supposed to be run automatically by a chosen node at different intervals of time.

    response = node.run_updater()
    print(response)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newrl-0.2.8.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

newrl-0.2.8-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file newrl-0.2.8.tar.gz.

File metadata

  • Download URL: newrl-0.2.8.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for newrl-0.2.8.tar.gz
Algorithm Hash digest
SHA256 253d7c48c943dfc6c406b08e101a568d63687b5de4fb4fa4e3fbf26b2d8ede8d
MD5 780923e11f535fddd36986d134fdf00f
BLAKE2b-256 71694ff82d6b872ca2f2e4d3ce04fb90d8abc52101a268df22085026bc3e5b42

See more details on using hashes here.

File details

Details for the file newrl-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: newrl-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for newrl-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 2fc551747eea977fe2c3751f5e0e9e2e366a7150d10b58f5528fa1e3ff46c50b
MD5 88e0c3ff01223a00f9f69ac65e8009c0
BLAKE2b-256 5d2911053134079a26e36ac0f2d70b96b5f50ce5e4ff2c032d6fbbbb3b32c64c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page