All pages
Powered by GitBook
1 of 7

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Python Peerplays

Introduction

Its the Python library for communicating with the Peerplays blockchain.

The code is maintained at https://gitlab.com/PBSA/PeerplaysIO/tools-libs/python-peerplays

Ids

1.2.x : accounts

1.3.x : assets

Notes

p.rpc.get_account_balances("jemshid", [])

p.rpc.get_global_properties

private-key = ["TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

def transfer(self, to, amount, asset, memo="", account=None, **kwargs):

Creating an Account

vThere are two ways to create an account.

  1. Python-Peerplays way: If you already have an account, that can be used to create another account.

  2. Faucet Way

Python-Peerplays Way

You need a funded account to create additional accounts. The funded account should be upgraded to create new accounts. To upgrade an account

Once the account is upgraded

p.create_account(account_name="new_account_name", registrar="the_upgraded_account", owner_key='TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV', active_key='TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV', memo_key='TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV')

Faucet Method

url =

requests.post(url, json=params)

Additional Methods

p.upgrade_account(account="account_name")
https://elizabeth-faucet.peerplays.download/api/v1/accounts

Installation

The python-peerplays library has following dependencies. Make sure that the above dependencies are installed, if not install with:

sudo apt-get install python3-dev build-essential libssl-dev\
 libffi-dev libxml2-dev libxslt1-dev zlib1g-dev

Now install python-peerplays as follows:

 pip install peerplays

Ipython is a rich interactive python command shell. It's recommended for trying out python-peerplays library. It can be installed with

pip install ipython

In case Python 2.7 is the default Python for your machine, repalce

pip with pip3

python with python3

ipython with ipython3

Ipython shell can be started with the command

ipython

To work with the latest development version of python-peerplays

git clone [email protected]:PBSA/PeerplaysIO/tools-libs/python-peerplays.git

cd python-peerplays

git checkout develop

To Do

  1. How to install system level from git for develop branch

params = {'account': {
    'name': 'new_account_name',
    'owner_key': 'TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV',
    'active_key': 'TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV',
    'memo_key': 'TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV',
    'refcode': '',
    'referrer': ''}}
    
p.transfer(to, amount, asset, memo="", account=None)

HRP / RBAC

Operations

Create Custom Permission

For example

Custom Permission Update

For example

Custom Permission Delete

For example

Custom Account Authority Create

For example

Custom Account Authority Update

For example

Custom Account Authority Delete

For example

RPC Info calls

p.custom_permission_create(
    permission_name,
    owner_account=None,
    weight_threshold=[],
    account_auths=[],
    key_auths=[],
    address_auths=[],
    )
    p.custom_permission_create(
        testperm1,
        owner_account="1.2.7",
        weight_threshold=1,
        account_auths=[["1.2.8", 1]])
p.custom_permission_update(
    permission_id,
    owner_account=None,
    weight_threshold=[],
    account_auths=[],
    key_auths=[],
    address_auths=[],
    )
            p.custom_permission_update(
                    permission_id,
                    weight_threshold=1,
                    account_auths=[["1.2.9", 2]],
                    owner_account="1.2.7"
            )
p.custom_permission_delete(
    permission_id,
    owner_account=None,
    )
            p.custom_permission_delete(
                    permission_id,
                    owner_account="1.2.7"
            )
p.custom_account_authority_create(
    permission_id,
    operation_type,
    valid_from,
    valid_to,
    owner_account=None,
    )
p.custom_account_authority_create(
                    permission_id,
                    0,
                    "2020-07-27T00:00:00",
                    "2030-07-27T00:00:00",
                    owner_account="1.2.7") 
p.custom_account_authority_update(
    auth_id,
    new_valid_from,
    new_valid_to,
    owner_account=None,
    )
p.custom_account_authority_update(
            authority_id,
            "2020-07-27T00:00:00",
            "2040-07-27T00:00:00",
            owner_account="1.2.7")
p.custom_account_authority_delete(
    auth_id,
    owner_account=None,
    )
    p.custom_account_authority_delete(
            authority_id,
            owner_account="1.2.7")
get_custom_permissions(account)
get_custom_permission_by_name(account, permission_name)
get_custom_account_authorities(account)
get_custom_account_authorities_by_permission_id(permission_id)
get_custom_account_authorities_by_permission_name(account, permission_name)
get_active_custom_account_authorities_by_operation(account, int operation_type)

Market Place

Operations

Create Offer

For example

Bid

For example

Cancel Offer

For example

Calls for info

Additional Info

For examples, refer to tests/test_market_place.py

p.create_offer(
    item_ids,                  # list of items
    issuer_id_or_name,
    minimum_price,             # asset type
    maximum_price,             # asset type
    buying_item,               # bool
    offer_expiration_date,     # "2020-09-18T11:05:39"
    memo=None,                 # optional
    )

Creating the wallet

All these experiments and examples are expected to be tried out in ipython command shell. Start the command shell with ipython

Node is the chain with which you wish to interact.

node = "wss://elizabeth.peerplays.download/api"

password = "password"

from peerplays import PeerPlays

p = PeerPlays(node)

To create a new wallet

p.newWallet(password)

Unlock the wallet

p.unlock(password)

Add private key / keys

p.wallet.addPrivateKey("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3")

Additional Methods

p.wallet.unlocked() #returns True if wallet is unlocked. Wallet needs to be unlocked to perform operations on the blockchain.

p.wallet.getAccounts() #Lists all the accounts associated with the private key.

p.create_offer(["1.31.5"], "1.2.9", {"amount":5,"asset_id":"1.3.0"}, {"amount":15,"asset_id":"1.3.0"}, False, "2030-09-18T11:05:39", "") 
p.create_bid(
    bidder_account_id_or_name,
    bid_price,                     # asset
    offer_id,                      # offer_id type, 1.29.x
    )
p.create_bid("1.2.10", {"amount":8,"asset_id":"1.3.0"}, offer["id"]) 
p.cancel_offer(
    issuer_account_id_or_name,
    offer_id,                     # offer_id type, 1.29.x
    )
p.cancel_offer("1.2.9", offer["id"]) 
p.rpc.list_offers(lower_id, limit)   # limt is number of entries requested as integer
p.rpc.list_sell_offers(lower_id, limit)
p.rpc.list_buy_offers(lower_id, limit)
p.rpc.list_offer_history(lower_id, limit)
p.rpc.get_offers_by_issuer(lower_id, issuer_account_id, limit)
p.rpc.get_offers_by_item(lower_id, nft_id_type_item, limit)
p.rpc.get_offer_history_by_issuer(lower_id, issuer_account_id, limit)
p.rpc.get_offer_history_by_item(lower_id, item, limit)
p.rpc.get_offer_history_by_bidder(lower_id, bidder_account_id, limit)

NFT

Non Fungible Tokens

Operations

Create NFT Meta

For example

Update NFT Meta

For example

Mint NFT

For example

Transfer NFT

For example

Approve Control over NFT

For example

Approve for all the tokens owned

For example

Info calls

p.rpc.nft_get_balance(owner)

p.rpc.nft_owner_of(token_id)

p.rpc.nft_get_approved(token_id)

p.rpc.nft_is_approved_for_all(owner, operator)

p.rpc.nft_get_name(nft_metadata_id)

p.rpc.nft_get_symbol(nft_metadata_id)

p.rpc.nft_get_token_uri(token_id)

p.rpc.nft_get_total_supply(nft_metadata_id)

p.rpc.nft_token_by_index(nft_metadata_id, token_idx)

p.rpc.nft_token_of_owner_by_index(nft_metadata_id, owner, token_idx)

p.rpc.nft_get_all_tokens()

p.rpc.nft_get_tokens_by_owner(owner)

Additional Info

For examples, refer to tests/test_nft.py

p.nft_metadata_create(
    owner_account_id_or_name,        # owner of nft meta
    name,                            # nft meta name
    symbol,                          # nft symbol
    base_uri,                        # nft uri
    is_transferable=True,
    is_sellable=True,
    )
p.nft_metadata_create("1.2.7", self.nameMetadata, self.nameMetadata, self.nameMetadata, revenue_partner="1.2.8", revenue_split=300, is_sellable=False, is_transferable=False)
p.nft_metadata_update(
    owner_account_id_or_name,
    nft_metadata_id,
    name,
    symbol,
    base_uri,
    is_transferable=True,
    is_sellable=True,
    )
p.nft_metadata_update("1.2.7", "1.30.11", self.nameMetadata + "m", self.nameMetadata + "m", self.nameMetadata + "m", "1.2.9", 400, True, True)
p.nft_mint(
    metadata_owner_account_id_or_name,
    metadata_id, 
    owner_account_id_or_name,
    approved_account_id_or_name,
    approved_operators,                     # list of operators
    token_uri,
    )
p.nft_mint("1.2.7", "1.30.11", "1.2.7", "1.2.7", "1.2.7", self.nameNft)
p.nft_safe_transfer_from(
    operator_,                # operator account name or id
    from_,
    to_,
    token_id,
    data,                     # notes as string
    )
p.nft_safe_transfer_from("1.2.7", "1.2.7", "1.2.9", "1.31.5", "whatever")
def nft_approve(
    operator_,
    approved,         # approved account id or name
    token_id,
    )
p.nft_approve("1.2.9", "1.2.8", "1.31.5")
def nft_set_approval_for_all(
    owner,
    operator_,
    approved,
    )
p.nft_set_approval_for_all("1.2.7", "1.2.10", True)