# client-sdk-python

[![Join the chat at https://gitter.im/ethereum/web3.py](https://badges.gitter.im/ethereum/web3.py.svg)](https://github.com/AlayaNetwork/client-sdk-python)

[![Build Status](https://circleci.com/gh/ethereum/web3.py.svg?style=shield)](https://github.com/AlayaNetwork/client-sdk-python)


## Description

client-sdk-python is a python sdk serving the Platon underlying chain. Interact with the underlying chain through the web3 object. At the bottom level, it communicates with local nodes through RPC calls. client-sdk-python can connect to any PlatON node that exposes the RPC interface.

The main functions are used to obtain block data, send transactions, interact with smart contracts, and other applications.


[client-sdk-python download link](https://github.com/AlayaNetwork/client-sdk-python)

## Quick start

### Special Note

- chain_id

  - 201030 is the chain id of the development network.

  - 201018 is the chain id of the main net.

### One part: installation

#### **1** Python environment requirements

 Support Python 3.6+ version

#### **2** You can use pip to install directly:

     pip install client-sdk-python


 Or download the code and use it in the python editor. git bash pull the source code, the following operations

    git clone -b 0.15.1-develop https://github.com/AlayaNetwork/client-sdk-python.git

> Where `0.15.1-develop` is the currently used branch.

### Second part: use

#### **1** Web3 mode

 Communication between Platon nodes through P2PMessage. The built-in Web3 mode is used between the node and the python sdk to send JSON-RPC requests, and connect to the node through HTTP, websocket, IPC and other methods.

#### **2** Node connection

- Take HTTP connection as an example, connect to a Platon node

  ```python
  w3 = Web3(HTTPProvider("http://localhost:6789"),chain_id = 100)
  platon = PlatON(w3)
  print(w3.isConnected())
  ```

  Where localhost:6789 is a node Url of Platon, please enter the Url of the accessible Platon node.

  platon is an instance of the platON class.

- Take Websocket connection as an example

  code show as below:

  ```python
  w3 = Web3(WebsocketProvider("ws://localhost:6790"),chain_id = 100)
  platon = PlatON(w3)
  print(w3.isConnected())
  ```

- Take IPC connection as an example

  code show as below:

  ```python
  w3 = Web3(IPCProvider("./platon.ipc"),chain_id = 100)
  platon = PlatON(w3)
  print(w3.isConnected())
  ```




#### 3 Basic API

##### Basic type encoding and decoding

- Web3.toBytes()
    Convert the input parameters to Bytes
    transfer:
    
    ```python
    >>> Web3.toBytes(0)
    b'\x00'
    >>> Web3.toBytes(0x000F)
    b'\x0f'
    ```

- Web3.toHex()

    Convert the input parameter to hexadecimal
  
    transfer:
  
    ```
    >>> Web3.toHex(b'\x00\x0F')
    '0x000f'
    >>> Web3.toHex(False)
    '0x0'
    ```

- Web3.toInt()

    Convert the input parameter to an integer
  
    transfer:
  
    ```python
    >>> Web3.toInt(0x000F)
    15
    >>> Web3.toInt(b'\x00\x0F')
    15
    ```

- Web3.toJSON()

    Convert the input parameters to json format
  
    transfer
  
    ```python
    >>> Web3.toJSON(3)
    '3'
    >>> Web3.toJSON({'one': 1})
    '{"one": 1}'
    ```

- Web3.toText()

    Convert input parameters to string format
  
    transfer
  
    ```python
    >>> Web3.toText(b'cowm\xc3\xb6')
    'cowmö'
    >>> Web3.toText(hexstr='0x636f776dc3b6')
    'cowmö'
    ```
##### Address detection

- Web3.isAddress()

    Check whether the input parameter is an approved address form
    
    transfer
    
    ```python
    >>> Web3.isAddress('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
    True
    ```

- Web3.isChecksumAddress()

    Check the checksum of the specified address, and return false for non-checksum addresses
    
    ```python
    >>> Web3.isChecksumAddress('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
    True
    >>> Web3.isChecksumAddress('0xd3cda913deb6f67967b99d67acdfa1712c293601')
    False
    ```

##### Cryptographic hash

- - Web3.sha3()

    Compile input parameters to Keccak-256
    
    transfer:
    
    ```python
    >>> Web3.sha3(0x678901)
    HexBytes('0x77cf3b4c68ccdb65991397e7b93111e0f7d863df3b26ebb053d0857e26486e6a')
    >>> Web3.sha3(text='txt')
    HexBytes('0xd7278090a36507640ea6b7a0034b69b0d240766fa3f98e3722be93c613b29d2e')
    ```

- Web3.soliditySha3()

    Compile the input abi_type and value to Keccak-256
    
    parameter:
    
    - value: true value.
    - abi_type: a list of strings in solidity format equal to value.
    
    transfer
    
    ```python
    >>> Web3.solidityKeccak(['uint8[]'], [[97, 98, 99]])
    HexBytes("0x233002c671295529bcc50b76a2ef2b0de2dac2d93945fca745255de1a9e4017e")
    
    >>> Web3.solidityKeccak(['address'], ["0x49EdDD3769c0712032808D86597B84ac5c2F5614"])
    HexBytes("0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882")
    ```


#### **4** On-chain query api

After successfully connecting with the nodes on the Platon chain, you can query the relevant information of the nodes on the chain through the api in platon

##### (1) platon.blockNumber

  Returns the current block number.

 Return value:

 An AttributeDict object whose parsed value is the number of the most recent block, Number type.



##### (2) platon.syncing

  Used to check whether the node is currently synchronized with the network.

  return value:

  An AttributeDict object with a resolved value of `Object` or `Bool`. If the node has not been synchronized with the network,
  It returns false, otherwise it returns a synchronization object with the following properties:

  - startingBlock-Number: Synchronization starting block number.

  - currentBlock-Number: currently synchronized block number.

  - highestBlock-Number: Estimated target synchronization block number.

  - knownStates-Number: Estimated states to be downloaded.

  - pulledStates-Number: downloaded states.


##### (3) platon.gasPrice

  Used to get the current gas price, which is determined by the median gas price of several recent blocks.

 Return value:

 An AttributeDict object whose parsed value is a string representing the current gas price, in VON.


##### (4) platon.accounts

  The method returns the list of accounts controlled by the current node.

  return value

  An AttributeDict object whose resolved value is an array of account addresses.


##### (5) platon.evidences

  Returns the storage content at the specified location of the account address.

  return value

  An AttributeDict object whose resolution value is the stored content of the account address.


##### (6) platon.consensusStatus

  Returns the consensus status information of the block tree where the current node is located.

  return value

  An AttributeDict object whose value is the public status information of all the blocks in the block tree.


##### (7) platon.getBalance(address)

  Used to get the balance of a specific account address in a specified block.

  parameter:

  - `address`: String-the account address to check the balance, bech32 address format, the beginning of lax is the testnet, the beginning of lat is the mainnet

  return value:

  An AttributeDict object whose parsed value is the balance string of the specified account address, in units of VON

Some code examples:

```python
from client_sdk_python import Web3, HTTPProvider
from client_sdk_python.eth import PlatON
from hexbytes import HexBytes

# get blockNumber syncing gasPrice accounts evidences consensusStatus
w3 = Web3(HTTPProvider("http://localhost:6789"),chain_id = 100)
platon = PlatON(w3)
block_number = platon.blockNumber
print(block_number)
print(platon.syncing)
print(platon.gasPrice)
print(platon.accounts)
print(platon.evidences)
print(platon.consensusStatus)

# get Balance
address ='lax1yjjzvjph3tw4h2quw6mse25y492xy7fzwdtqja'
balance = platon.getBalance(address)
print(balance)

#Output
385274
False
100000000
['lax1yjjzvjph3tw4h2quw6mse25y492xy7fzwdtqja','lax1qqqjkfwu854vf3ze2dpy5gctmxy3gdgzsngj66']
{}
AttributeDict({'blockTree': AttributeDict({'root': AttributeDict({'viewNumber': 22,'blockHash': '0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d','blockNumber': 392226,'receiveTime': 05'receiveTime': 58.440430021+08:00','qc': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d','blockNumber': 392 5226,'blockIndex': 392 5226, '0x83a517492b9052de25d3b88413f070becff1e995167094b33805bfaf640b8d1499304844f08478f0525c44e7eb9ec70000000000000000000000000000000000', 'validatorSet': '_xxx'}), 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'childrenHash': [ '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90']}), 'blocks': AttributeDict ({' 392226 ': AttributeDict ({' 0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d ': AttributeDict({'viewNumber': 22,'blockHash': '0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674 d','blockNumber': 392226,'receiveTime': '2020-09-15T18:05:58.440430021+08:00','qc': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash ':' 0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d ',' blockNumber ': 392226,' blockIndex ': 5,' signature ':' 0x83a517492b9052de25d3b88413f070becff1e995167094b33805bfaf640b8d1499304844f08478f0525c44e7eb9ec70000000000000000000000000000000000 ',' validatorSet ':' _xxx '}),' parentHash ':' 0x0000000000000000000000000000000000000000000000000000000000000000 ',' childrenHash ': [' 0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90 ']})}),' 392227 ': AttributeDict ({' 0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90 ': AttributeDict ({' viewNumber ': 22,' blockHash ':' 0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90 ',' blockNumber ': 392227,' receiveTime ':' 2020-09 -15T18:05:59.542161134+08:00','qc': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x69ea999a1bdb006bb9b113f20047a3d3ae7 9433abc1749e4fa1ec4082dcb0e90 ',' blockNumber ': 392227,' blockIndex ': 6,' signature ':' 0x50bcc710ac0182f311065dfcb4b1c8b378788bcfe53217d6f5b29e3178508bec5557eaf7e9d360930c69c43a091e5f1800000000000000000000000000000000 ',' validatorSet ':' _xxx '}),' parentHash ':' 0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d ',' childrenHash ': [' 0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294 '] }))), '392228': AttributeDict({'0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294': AttributeDict({'viewNumber': 22,'blockHash': '0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294': AttributeDict({'viewNumber': 22,'blockHash': '0x314adeb1cd8294228' 06:00.642317619+08:00','qc': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294','signatureNumber': 392 7,228,'blockIndex ': '0x505b4a9e0ed0cb3e26b2b327013bcde06350c7b2926126bbaa02417e386b0ecddc31201ec66e8a29e3c86714d669899000 000000000000000000000000000000','validatorSet':'_xxx'}),'parentHash': '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90','childrenHash': []}))))))','StateDictview(AttributeDict') 'epoch': 1569,'viewNumber': 22,'executing': AttributeDict({'blockIndex': 7,'finish': True}),'viewchange': AttributeDict({'viewchanges': AttributeDict({})} ),'lastViewchange': None,'hadSendPrepareVote': AttributeDict({'votes': [AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x201c9308eb4e0af12b98d64694837db7a5ab430blockaa71'857db90392' blockIndex': 0,'validatorIndex': 1,'parentQC': AttributeDict(('epoch': 1569,'viewNumber': 21,'blockHash': '0x3cc758aa857621036e55cede20943ffd1a3b7e1ebc38dffcc690d4804f706dd0','blockNumber': 392220,'blockNumber': 392220, 'signature': '0xb3a89b39e9345d37ea7db2985132a3adb55abb906cd975f137eb608f55be7ea7657b0ecc0ccfa99d3caebb25a088018d00000000000000000000000000000000','validatorSet':'_xxx')),'s ignature ':' 0x599205f55ce4a191405fb5c7ad4a3961bb95a93206525b8218777023f47114a611146a40921f537478339375844cb10b00000000000000000000000000000000 '}), AttributeDict ({' epoch ': 1569,' viewNumber ': 22,' blockHash ':' 0xf6fff5626fc1fd235bb224a4d1b3f68ccd1f9f56ad4d6dff428d33b4b10cff7f ',' blockNumber ': 392222,' blockIndex ': 1,' validatorIndex ': 1, 'parentQC': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x201c9308eb4e0af12b98d64694837db7a59780ab430aa71ccfdb90741d41f857', 'blockNumber': 392221, 'blockIndex': 0, 'signature': '0xfbb64c0d0bd6f531f4d9b6303e9b3ede59deb1877c7a31bd95c0403dcfc32dec7b8060574616d500735a2d734d21e90300000000000000000000000000000000', 'validatorSet' : '_xxx'}), 'signature': '0x422a227b80667cd3f38ff794018ad3f634c0aafdbcc08a9dddff2f46b3d66f829c217dca47add729817a72dae169040000000000000000000000000000000000'}), AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x812e7f19e6a281928ac77767300560b8ed633d0c45f53a05b0163ea807898913', 'blockNumber': 392223, 'b lockIndex': 2,'validatorIndex': 1,'parentQC': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0xf6fff5626fc1fd235bb224a4d1b3f68ccd1f9f56ad4d6dff428d33b4b10cff7f','Numberblock'Index: 392 1, 'signature': '0x5dc7f6461e0078b7e474badc1f7b3e0716b52f5f2f2ddcd144bd738e74246d1e5ee3780e0d4f7771b3afd5b10936019500000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature': '0xaedbc8885b066d99905c7813302ce699b895761a1b4ab83efda28dc3b5901b585ada31df67932b68e52edd663f651e9200000000000000000000000000000000'}), AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x45f49937c4ea54b08d36fc1223fd819da11f709b3827217225c235a0ef9f89a8' ,'blockNumber': 392224,'blockIndex': 3,'validatorIndex': 1,'parentQC': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x812e7f19e6a281928ac77767300560b8ed633d0c45f53a05b0163eablockNumber'913:', 392223,'blockIndex': 2,'signature': '0xd3a08cfd6c3a166e1d31dd1e58bb9eb1960bebcfc38ebad0eb0880ab30b2e46112c5 14980050159ad235615381ac820d00000000000000000000000000000000 ',' validatorSet ':' _xxx '}),' signature ':' 0xb52fb84d8ea31918023e695fe3619ba14a1335f6455e6ab42559d7e38c9bcef8105d7c33d433f6fb7eb8d524b1afb58b00000000000000000000000000000000 '}), AttributeDict ({' epoch ': 1569,' viewNumber ': 22,' blockHash ':' 0x0341dcfab2ee1ec61b5cd380bd8445ab0a17819cc4f633ee0b3a4ca211c717f9 ',' blockNumber ': 392225,'blockIndex': 4,'validatorIndex': 1,'parentQC': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x45f49937c4ea54b08d36fc1223fd819da11f709b3827217225c235a0ef9f89'blockIndex: 392224,'blockNumber : 3, 'signature': '0xd837920786bce9ea276ff3a6505dc8f48db18e9f7f4272b66dff966c904bbb83adb70f425af9c99a30957a8eae3cf30b00000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature': '0x63dd1a1f8331320b2be8bd04abb2bae53f67fe9c14f70863723a86ccf329d4d95c9446aae360081935df5a7f2ac8681300000000000000000000000000000000'}), AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x9 2e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d','blockNumber': 392226,'blockIndex': 5,'validatorIndex': 1,'parentQC': Dict(('epochAttribute': 1569,'viewNumber': 22,'blockHec7, 11, 37, 14b,, and ': 392225,' blockIndex ': 4,' signature ':' 0x442a6e1c25857ac5ba84b16ab38918fba3c75681dcf623eacf23d5dbafd293cd0d3d617472e60dccd343c9444c4d428500000000000000000000000000000000 ',' validatorSet ':' x_xx '}),' signature ':' 0xf885e975ff4828d1f10be4dd61b7cd4e362d0f4a0b79af9d7a2ac34209341ee79d76281ec7b205f834e5c2c00c0c398800000000000000000000000000000000 '}), AttributeDict ({' epoch ': 1569,' viewNumber ' : 22,'blockHash': '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90','blockNumber': 392227,'blockIndex': 6,'validatorIndex': 1,'parentQC': AttributeDict({'epochNumberHash': 22 ': '0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d','blockNumber': 392226,'blockInde x ': 5,' signature ':' 0x83a517492b9052de25d3b88413f070becff1e995167094b33805bfaf640b8d1499304844f08478f0525c44e7eb9ec70000000000000000000000000000000000 ',' validatorSet ':' _xxx '}),' signature ':' 0xbe0d77590be62ec7cb0f5fd2dd5071aa6d97e8b909fd05cc80f10e6e58f0984adeeb7078f2c9a99e4a08e00102d4209900000000000000000000000000000000 '}), AttributeDict ({' epoch ': 1569,' viewNumber ': 22,' blockHash ': '0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294','blockNumber': 392228,'blockIndex': 7,'validatorIndex': 1,'parentQC': AttributebbDict({'epoch': 1569, '0be69a , 'blockNumber': 392227, 'blockIndex': 6, 'signature': '0x50bcc710ac0182f311065dfcb4b1c8b378788bcfe53217d6f5b29e3178508bec5557eaf7e9d360930c69c43a091e5f1800000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature': '0x7305573c2655de2537e744ef1411ea55e450f8879a19274ede2455f40975f59c1b9df25d3e311464fb5cbd2398fcd48600000000000 000000000000000000000'})]}),'pendingPrepareVote': AttributeDict({'votes': []}),'viewBlocks': AttributeDict({'0': AttributeDict({'hash': '0x201c9308eb4e0af12b98d64694837db7a59780',number 392221,'blockIndex': 0}), '1': AttributeDict({'hash': '0xf6fff5626fc1fd235bb224a4d1b3f68ccd1f9f56ad4d6dff428d33b4b10cff7f','number': 392222,'blockIndex': AttributeDict( 1)),'number': 392222,'hash'{ 1}), '0x812e7f19e6a281928ac77767300560b8ed633d0c45f53a05b0163ea807898913','number': 392223,'blockIndex': 2}), '3': AttributeDict({'hash': '0x45f49937c4ea70954b08d36fc1223fdefda11f2242222423a2709'b3827225 : AttributeDict({'hash': '0x0341dcfab2ee1ec61b5cd380bd8445ab0a17819cc4f633ee0b3a4ca211c717f9','number': 392225,'blockIndex': 4)), '5': AttributeDict({'hash': '0x0341dcfab2ee1ec61b5cd380bd8445ab0a17819cc4f633ee0b3a4ca211c717f9','number': 392225,'blockIndex': 4}), '5': AttributeDict({'hash': : 5}), '6': AttributeDict({'hash': '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4f a1ec4082dcb0e90','number': 392227,'blockIndex': 6}), '7': AttributeDict({'hash': '0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294','number': 392228,'block})','view 7Qcs')' ': AttributeDict({'maxIndex': 7,'qcs': AttributeDict({'0': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x201c9308eb4e0af12b98d64694837db7a58579780ab430aa71ccfdb90741d41f:', '221 , 'blockIndex': 0, 'signature': '0xfbb64c0d0bd6f531f4d9b6303e9b3ede59deb1877c7a31bd95c0403dcfc32dec7b8060574616d500735a2d734d21e90300000000000000000000000000000000', 'validatorSet': '_xxx'}), '1': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0xf6fff5626fc1fd235bb224a4d1b3f68ccd1f9f56ad4d6dff428d33b4b10cff7f ','blockNumber': 392222,'blockIndex': 1,'signature': '0x5dc7f6461e0078b7e474badc1f7b3e0716b52f5f2f2ddcd144bd738e74246d1e5ee3780e0d4f7771b3afd5b109' : 22, 'blockHash': '0x812e7f19e6a281928ac77767300560b8ed633d0c45f53a05b0163ea807898913', 'blockNumber': 392223, 'blockIndex': 2, 'signature': '0xd3a08cfd6c3a166e1d31dd1e58bb9eb1960bebcfc38ebad0eb0880ab30b2e46112c514980050159ad235615381ac820d00000000000000000000000000000000', 'validatorSet': '_xxx'}), '3': AttributeDict ({ 'epoch ': 1569,' viewNumber ': 22,' blockHash ':' 0x45f49937c4ea54b08d36fc1223fd819da11f709b3827217225c235a0ef9f89a8 ',' blockNumber ': 392224,' blockIndex ': 3,' signature ':' 0xd837920786bce9ea276ff3a6505dc8f48db18e9f7f4272b66dff966c904bbb83adb70f425af9c99a30957a8eae3cf30b00000000000000000000000000000000 ',' validatorSet ':' _xxx '}),' 4 ': AttributeDict ({' epoch ': 1569,' viewNumber ': 22,' blockHash ':' 0x0341dcfab2ee1ec61b5cd380bd8445ab0a17819cc4f633ee0b3a4ca211c717f9 ',' blockNumber ': 392225,' blockIndex ': 4,' signature ':' 0x442a6e1c25857ac5ba84b16ab38918fba3c75681dcf623eacf23d5dbafd293cd0d3d617472e60dccd343c9444c4d428500000000000000000000000000000000 ',' validatorSet ':' x_xx'}), '5': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d', 'blockNumber': 392226, 'blockIndex': 5, 'signature': '0x83a517492b9052de25d3b88413f070becff1e995167094b33805bfaf640b8d1499304844f08478f0525c44e7eb9ec70000000000000000000000000000000000', 'validatorSet' :'_xxx')), '6': AttributeDict(('epoch': 1569,'viewNumber': 22,'blockHash': '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90','blockNumber': 392 6,227,'blockIndex': '0x50bcc710ac0182f311065dfcb4b1c8b378788bcfe53217d6f5b29e3178508bec5557eaf7e9d360930c69c43a091e5f1800000000000000000000000000000000', 'validatorSet': '_xxx'}), '7': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294', 'blockNumber': 392228, 'blockIndex' : 7,'signature': '0x505b4a9e0ed0cb3e26b2b327013bcde06350c7b2926126bbaa02417e386b0ecddc31201ec66e8a29e3c86714d669899000000000000000 000000000000000000','validatorSet':'_xxx'}))))),'viewVotes': AttributeDict({'votes': AttributeDict({'0': AttributeDict({'votes': AttributeDict({'1': AttributeDict ({'epoch': 1569,'viewNumber': 22,'blockHash': '0x201c9308eb4e0af12b98d64694837db7a59780ab430aa71ccfdb90741d41f857','blockNumber': 392221,'blockIndex': 0,'validatorIndex': 1,'parentQC': AttributeDict({'epoch' : 1569, 'viewNumber': 21, 'blockHash': '0x3cc758aa857621036e55cede20943ffd1a3b7e1ebc38dffcc690d4804f706dd0', 'blockNumber': 392220, 'blockIndex': 9, 'signature': '0xb3a89b39e9345d37ea7db2985132a3adb55abb906cd975f137eb608f55be7ea7657b0ecc0ccfa99d3caebb25a088018d00000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature' : '0x599205f55ce4a191405fb5c7ad4a3961bb95a93206525b8218777023f47114a611146a40921f537478339375844cb10b00000000000000000000000000000000')))))), '1': AttributeDict({'votes': AttributeDict({'1', '224xfbbd': AttributeDict({'1', '224xfbbd': AttributeDict('1') 1f9f56ad4d6dff428d33b4b10cff7f','blockNumber': 392222,'blockIndex': 1,'validatorIndex': 1,'parentQC': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x201c9308eb4e0af12b71ccf'85790741db ': 392221,' blockIndex ': 0,' signature ':' 0xfbb64c0d0bd6f531f4d9b6303e9b3ede59deb1877c7a31bd95c0403dcfc32dec7b8060574616d500735a2d734d21e90300000000000000000000000000000000 ',' validatorSet ':' _xxx '}),' signature ':' 0x422a227b80667cd3f38ff794018ad3f634c0aafdbcc08a9dddff2f46b3d66f829c217dca47add729817a72dae169040000000000000000000000000000000000 '})})}),' 2 ': AttributeDict ({' votes': AttributeDict(('1': AttributeDict(('epoch': 1569,'viewNumber': 22,'blockHash': '0x812e7f19e6a281928ac77767300560b8ed633d0c45f53a05b0163ea807898913','blockNumber': 392223,'blockHash': 1,'validatorIndex': 1, ,'parentQC': AttributeDict(('epoch': 1569,'viewNumber': 22,'blockHash': '0xf6fff5626fc1fd235bb224a4d1b3f68ccd1f9f56ad4d6dff428d33b4b10cff7f','blockNumber' : 392222, 'blockIndex': 1, 'signature': '0x5dc7f6461e0078b7e474badc1f7b3e0716b52f5f2f2ddcd144bd738e74246d1e5ee3780e0d4f7771b3afd5b10936019500000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature': '0xaedbc8885b066d99905c7813302ce699b895761a1b4ab83efda28dc3b5901b585ada31df67932b68e52edd663f651e9200000000000000000000000000000000'})})}), '3': AttributeDict ({ 'votes ': AttributeDict({'1': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x45f49937c4ea54b08d36fc1223fd819da11f709b3827217225c235a0ef9f89a8','blockNumber': 392224,'blockNumber': 3, 'parentQC': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x812e7f19e6a281928ac77767300560b8ed633d0c45f53a05b0163ea807898913', 'blockNumber': 392223, 'blockIndex': 2, 'signature': '0xd3a08cfd6c3a166e1d31dd1e58bb9eb1960bebcfc38ebad0eb0880ab30b2e46112c514980050159ad235615381ac820d00000000000000000000000000000000', 'validatorSet' :'_xxx'}),'signature': '0xb52fb84d8ea31918023e695fe3619ba14a 1335f6455e6ab42559d7e38c9bcef8105d7c33d433f6fb7eb8d524b1afb58b00000000000000000000000000000000 '})})}),' 4 ': AttributeDict ({' votes': AttributeDict ({ '1': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x0341dcfab2ee1ec61b5cd380bd8445ab0a17819cc4f633ee0b3a4ca211c717f9', 'blockNumber': 392225,'blockIndex': 4,'validatorIndex': 1,'parentQC': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x45f49937c4ea54b08d36fc1223fd819da11f709b3827217225c235'a0,392224 , 'blockIndex': 3, 'signature': '0xd837920786bce9ea276ff3a6505dc8f48db18e9f7f4272b66dff966c904bbb83adb70f425af9c99a30957a8eae3cf30b00000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature': '0x63dd1a1f8331320b2be8bd04abb2bae53f67fe9c14f70863723a86ccf329d4d95c9446aae360081935df5a7f2ac8681300000000000000000000000000000000'})})}), '5': AttributeDict ({ 'votes': AttributeDict({'1': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x92e3229453574aa2a7120e3b0dd44d3b1b 304465418a129dcc72124414b9674d','blockNumber': 392226,'blockIndex': 5,'validatorIndex': 1,'parentQC': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x0341dcfab2ee1ec61b5cd380bd38445ab0a71711 ': 392225,' blockIndex ': 4,' signature ':' 0x442a6e1c25857ac5ba84b16ab38918fba3c75681dcf623eacf23d5dbafd293cd0d3d617472e60dccd343c9444c4d428500000000000000000000000000000000 ',' validatorSet ':' x_xx '}),' signature ':' 0xf885e975ff4828d1f10be4dd61b7cd4e362d0f4a0b79af9d7a2ac34209341ee79d76281ec7b205f834e5c2c00c0c398800000000000000000000000000000000 '})})}),' 6 ': AttributeDict ({' votes': AttributeDict({'1': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90','blockNumber': 392 6,227,'validatorIndex': 392 6,227, ,'parentQC': AttributeDict(('epoch': 1569,'viewNumber': 22,'blockHash': '0x92e3229453574aa2a7120e3b0dd44d3b1b304465418a129dcc72124414b9674d','blockNumber' : 392226, 'blockIndex': 5, 'signature': '0x83a517492b9052de25d3b88413f070becff1e995167094b33805bfaf640b8d1499304844f08478f0525c44e7eb9ec70000000000000000000000000000000000', 'validatorSet': '_xxx'}), 'signature': '0xbe0d77590be62ec7cb0f5fd2dd5071aa6d97e8b909fd05cc80f10e6e58f0984adeeb7078f2c9a99e4a08e00102d4209900000000000000000000000000000000'})})}), '7': AttributeDict ({ 'votes ': AttributeDict({'1': AttributeDict({'epoch': 1569,'viewNumber': 22,'blockHash': '0x314adeb1ded15f49579ae2bc44d0b060d1d57905e9ddcd8da8ad1628bbee5294','blockNumber': 392228,'blockatorIndex': 7,'validatorIndex': 7, 'parentQC': AttributeDict ({ 'epoch': 1569, 'viewNumber': 22, 'blockHash': '0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90', 'blockNumber': 392227, 'blockIndex': 6, 'signature': '0x50bcc710ac0182f311065dfcb4b1c8b378788bcfe53217d6f5b29e3178508bec5557eaf7e9d360930c69c43a091e5f1800000000000000000000000000000000', 'validatorSet' :'_xxx'}),'signature': '0x7305573c2655de2537e744ef1411ea55e4 50f8879a19274ede2455f40975f59c1b9df25d3e311464fb5cbd2398fcd48600000000000000000000000000000000')))))))))))),'highestQCBlock': AttributeDict({'hash': '0x314adeb1cd8392905e9ae2dbc8d57392905e9060' 0x69ea999a1bdb006bb9b113f20047a3d3ae79433abc1749e4fa1ec4082dcb0e90','number': 392227}),'highestCommitBlock': AttributeDict({'hash': '0x92e3229453574aa2a7120e3b0dd44d3b4}number: 392dcc721304465a4)
220855883097298041197912187592864814478435487109452369765200775161577471

```

##### (8) platon.getStorageAt()

  Return the contents of the specified location of an address

  transfer:

  ```
  platon.getStorageAt(address, position [, defaultBlock])
  ```

  parameter:

- `address`: String-the address to be read.
- `position`: Number-index number in storage.
- `defaultBlock`: Number|String-Optional, use this parameter to override the platon.defaultBlock attribute value.


return value:

An AttributeDict object whose parsed value is the content of the specified location in the storage.

##### (9) platon.getCode

  Returns the code at the specified address.

  transfer:

  ```
  platon.getCode(address [, defaultBlock])
  ```

  parameter:

- `address`: String-the address of the code to be read.
- `defaultBlock`: Number|String-Optional, use this parameter to override the platon.defaultBlock attribute value.


return value:

An AttributeDict object whose parsed value is the code string at the specified address.



##### (10) platon.getBlock()

  Returns the block corresponding to the specified block number or block hash.

  transfer:

  ```
  platon.getBlock(blockHashOrBlockNumber [, returnTransactionObjects])
  ```

  parameter:

- `blockHashOrBlockNumber`: String|Number-Block number or block hash value, or use the following string: "genesis", "latest" or "pending".
- `returnTransactionObjects`: Boolean-Optional, the default value is false. When set to true, all transaction details will be included in the return block, otherwise only the transaction hash will be returned.


return value:

An AttributeDict object whose parsed value is a block object that meets the search conditions and has the following fields:

- number-Number: block number, the block in pending state is null.

- hash 32 Bytes-String: block hash, the block in pending state is null.

- parentHash 32 Bytes-String: parent block hash.

- nonce 8 Bytes-String: The hash of the generated proof-of-work, the pending block is null.

- sha3Uncles 32 Bytes-String: SHA3 value of the uncle data in the block.

- logsBloom 256 Bytes-String: The bloom filter of the log in the block, and the block in the pending state is null.

- transactionsRoot 32 Bytes-String: the root node of the transaction tree in the block.

- stateRoot 32 Bytes-String: The root node of the final state tree in the block.

- miner-String: The address of the miner receiving the reward.

- difficulty-String: difficulty value of the block.

- totalDifficulty-String: The total difficulty value of the whole chain up to the block.

- extraData-String: Block "extra data" field.

- size-Number: block size in bytes.

- gasLimit-Number: The maximum gas value allowed in the block.

- gasUsed-Number: The total amount of gas used by all transactions in the block.

- timestamp-Number: the unix timestamp of the block.

- transactions-Array: transaction object array, or 32-byte transaction hash value, depending on the setting of returnTransactionObjects.

- uncles-Array: Uncle block hash value array.

  ##### (11) platon.getBlockTransactionCount()

  The method returns the number of transactions in the specified block.

  transfer:

  ```
  platon.getBlockTransactionCount(blockHashOrBlockNumber)
  ```

  parameter:

- `blockHashOrBlockNumber`: String|Number-Block number or hash value of the block, or use the following string: "genesis", "latest" or "pending" to specify the block


return value:

An AttributeDict object whose parsed value is the number of transactions in the specified block, of type Number.

  

##### (12) platon.getTransaction()

  Returns the transaction object with the specified hash value.

  transfer:

  ```
platon.getTransaction(transactionHash)
  ```

  parameter:

- `transactionHash`: String-the hash value of the transaction

​    

  return value:

  An AttributeDict object whose parsed value is a transaction object with a given hash value. Refer to platon.waitForTransactionReceipt for the specific content description of this object.

  

##### (13) platon.getRawTransaction()

  Returns the HexBytes value of the transaction object with the specified hash value.

  transfer:

  ```
  platon.getRawTransaction(transactionHash)
  ```

  parameter:

- `transactionHash`: String-the hash value of the transaction

  return value:

  An object of HexBytes values.

  

##### (14) platon.getTransactionFromBlock()

  Returns the transaction object of the specified index number in the specified block.

  transfer:

  ```
 getTransactionFromBlock(hashStringOrNumber, indexNumber)
  ```

  parameter:

- `hashStringOrNumber`: String-the block number or the hash value of the block, or use the following string: "genesis, "latest" or "pending" to specify the block.
- `indexNumber`: Number-transaction index position.

  return value:

  An AttributeDict object whose parsed value is a transaction object. Refer to platon.getTransaction() for the specific content description of the object.

  

##### (15) platon.getTransactionByBlock()

  Returns the transaction object of the specified index number in the specified block.

  transfer:

  ```
  platon.getTransactionByBlock(hashStringOrNumber, indexNumber)
  ```

  parameter:

- `hashStringOrNumber`: Number |String-the block number or the hash value of the block, or use the following string: "genesis, "latest" or "pending" to specify the block.
- `indexNumber`: Number-transaction index position.

  return value:

  An AttributeDict object whose parsed value is a transaction object. Refer to platon.getTransaction() for the specific content description of the object.

#### **5** Send transaction api on chain:

##### (1) sendTransaction(transactionObject)

  Submit a transaction to the platon chain (transaction that has been signed by the node and has not yet been submitted)

  parameter:

- `transactionObject`: Object-The transaction object to be sent, including the following fields:
  - from-String|Number: The account address of the transaction sender. If this field is not set, the platon.defaultAccount attribute value is used. Can be set as an address or the index number in the local wallet platon.accounts.wallet.
  - to-String: Optional, the destination address of the message, this field is null for contract creation transactions.
  - value-Number|String|BN|BigNumber: (optional) The value transferred for the transaction in VON, also the endowment if it’s a contract-creation transaction.
  - gas-Number: optional, default value: to be determined, the total amount of gas used for transactions, unused gas will be refunded.
  - gasPrice-Number|String|BN|BigNumber: Optional, the gas price of the transaction, the unit is VON, the default value is platon.gasPrice attribute value.
  - data-String: Optional, it can be an ABI string containing contract method data, or the initialization code in the contract creation transaction.
  - nonce-Number: Optional, use this field to cover pending transactions that use the same nonce value.

  return value:

  The return value of the `platon.sendTransaction()` method is a 32-byte transaction hash value.

  

##### (2) waitForTransactionReceipt(transaction_hash, timeout)

  Return the receipt object of the specified transaction within the specified time.

  parameter:

- `transaction_hash`: String-the hash value of the transaction.
- `timeout`: Number- Optional waiting time length, in seconds. The default is 120.

  return value:

  An AttributeDict object whose parsed value is the receipt object of the transaction or null. The receipt object has the following fields:

- `blockHash` 32 Bytes-String: The hash value of the exchange in the block.
- `blockNumber`-Number: The number of the exchange in the block.
- `transactionHash` 32 Bytes-String: hash value of the transaction.
- `transactionIndex`-Number: The index position of the transaction in the block.
- `from`-String: The address of the transaction sender.
- `to`-String: The address of the recipient of the transaction. For the transaction that created the contract, the value is null.
- `contractAddress`-String: For the transaction that creates a contract, the value is the address of the created contract, otherwise it is null.
- `cumulativeGasUsed`-Number: The cumulative total gas usage of the block where the transaction is executed.
- `gasUsed`- Number: the total amount of gas for this transaction.
- `logs`-Array: The array of log objects generated by the transaction.

  

Examples of how to use sendTransaction and waitForTransactionReceipt are as follows:

```python
# sendtransaction
to ='lax1qqqjkfwu854vf3ze2dpy5gctmxy3gdgzsngj66'
w3.personal.unlockAccount(address, "password", 999999)
data = {
    "from": address,
    "to": to,
    "value": 0x10909,
    "gas": 1000000,
    "gasPrice": 1000000000,
}
transaction_hex = HexBytes(platon.sendTransaction(data)).hex()
result = platon.waitForTransactionReceipt(transaction_hex)
print(result)

#Output
AttributeDict(('blockHash': HexBytes('0x7bfe17689560c773b1cade579f1bd2cf85aeea9f75177e0e06bcdb4aeebd31a8'),'blockNumber': 385507,'contractAddress': None,'cumulativeGaswUsedjj25 [], 'logsBloom': HexBytes ( ' '), 'status': 1, 'to': 'lax1qqqjkfwu854vf3ze2dpy5gctmxy3gdgzsngj66', 'transactionHash': HexBytes ( '0x377fcd0dfb5e294041fe4274175ed7fce253973fac7abf4e4ff808b5099a454c'), 'transactionIndex': 0})
```

##### (3) platon.getTransactionReceipt()

  Returns the receipt object of the specified transaction.
  If the transaction is pending, it returns null.

  transfer:

  ```
  platon.getTransactionReceipt(hash)
  ```

  parameter:

- `hash`: String-the hash value of the transaction

  return value:

  An AttributeDict object whose parsed value is the receipt object of the transaction or null. Refer to platon.waitForTransactionReceipt for the specific content description of this object.  

##### (4) platon.getTransactionCount()

  Returns the number of transactions issued by the specified address.

  transfer:

  ```
  platon.getTransactionCount(address [, defaultBlock])
  ```

  parameter:

- `address`: String-the address of the account to be queried.
- `defaultBlock`: Number|String-Optional, set this parameter to override the platon.defaultBlock property value.

  return value:

  An AttributeDict object whose resolved value is the number of transactions issued by the specified address.  

##### (6) platon.sendRawTransaction()

  Submit a signed serialized transaction to the platon chain

  ```
platon.sendRawTransaction(signTransaction, private-key)
  ```

  parameter:

- `signTransaction`: Object-The signed transaction object to be sent, including the following fields:

  - from-String|Number: The account address of the transaction sender. If this field is not set, the platon.defaultAccount attribute value is used. Can be set as an address or the index number in the local wallet platon.accounts.wallet    .
  - to-String: Optional, the destination address of the message, this field is null for contract creation transactions   . 
  - value-Number|String|BN|BigNumber: (optional) The value transferred for the transaction in VON, also the endowment if it’s a contract-creation transaction.

  - gas-Number: optional, default value: to be determined, the total amount of gas used for transactions, unused gas will be refunded.

  - gasPrice-Number|String|BN|BigNumber: Optional, the gas price of the transaction, in VON, the default value is platon.gasPrice property value.

  - data-String: Optional, it can be an ABI string containing contract method data, or the initialization code in the contract creation transaction.

  - nonce-Number: Optional, use this field to cover pending transactions that use the same nonce value.

- private-key: the private key used for signing.

  return value:

  The return value is HexBytes containing the 32-byte transaction hash value.

  

##### (7) platon.replaceTransaction()

  Send a new transaction new_transaction to replace the original transaction transaction_hash (pending state).

  transfer:

  ```python
  platon.replaceTransaction`(transaction_hash,new_transaction)
  ```

  parameter:

- transaction_hash-string: The hash value of the transaction in the pending state.

- new_transaction-dict: transaction object, including fields consistent with transactionObject in sendTransaction.

  return value:

   The hash value of new_transaction.

  

##### (8) platon.generateGasPrice()

  Use the selected gas price strategy to calculate a gas price

  transfer:

  ```
  platon.generateGasPrice(gas_price_strategy)
  ```

 Return value:

 The gas price value in wei



##### (9) platon.setGasPriceStrategy()

  Set the selected gas price strategy

  transfer:

  ```
  platon.setGasPriceStrategy(gas_price_strategy)
  ```

  parameter:

- gas_price_strategy: (web3, transaction_params), must be a signature method.

  return:

- The gas price value in wei

##### (10) platon.modifyTransaction()

  Send new parameters to modify the pending transaction

  transfer:

  ```python
  platon.modifyTransaction(transaction_hash, **transaction_params)
  ```

  parameter:

- transaction_hash -string: The hash value of the transaction in the pending state.
- transaction_params: keyword statements corresponding to the parameters of transaction_hash. If value=1000, change the value value in the original transaction to 1000.

  return:

   The hash value of the revised transaction  .

##### (11) platon.sign()

  The method uses the specified account to sign the data, and the account must be unlocked first.

  transfer:

  ```
  platon.sign(dataToSign, address)
  ```

  parameter:

- `dataToSign`: String-The data to be signed. For the string, it will first use the utils.utf8ToHex() method to convert it to hexadecimal.
- `address`: String|Number-The account address used for signing. Or the address or its serial number in the local wallet platon.accounts.wallet

  return value:

   The signature result string.  

##### (12) platon.estimateGas()

  Estimate the gas usage of the transaction by executing a message call.

  transfer:

  ```
  platon.estimateGas(callObject)
  ```

  parameter:

- `callObject`: Object-transaction object, its from attribute is optional

  return value:

  The amount of gas used for simulation calls.



#### 6 Other api

##### (1) platon.filter

  Generate a new filter, according to the different parameters, generate different types of filters

  transfer:

  ```
  platon.filter(params)
  ```

  parameter:

- params
  - 'latest', create a filter in the node to be notified when a new block is generated. To check whether the status has changed.
  - 'pending', create a filter in the node to notify when a pending transaction occurs. To check whether the status has changed.
  - Dictionary data, create a filter to notify when the client receives a matching whisper message.


​    

  ```python
  >>> platon.filter('latest')
  <client_sdk_python.utils.filters.BlockFilter object at 0x0000020640DA1048>
  >>> platon.filter('pending')
  <client_sdk_python.utils.filters.TransactionFilter object at 0x0000020640DA7C08>
  >>> platon.filter({'fromBlock': 1000000,'toBlock': 1000100,'address':'lax1yjjzvjph3tw4h2quw6mse25y492xy7fzwdtqja'})
  <client_sdk_python.utils.filters.LogFilter object at 0x0000020640B09D88>
  ```



##### (2) platon.getFilterChanges()

  Polling the specified filter and returning the newly generated log array since the last poll.

  transfer:

  ```
  platon.getFilterChanges(filter_id)
  ```

  parameter:

- filter_id: filter_id of the specified filter.

  

  Example:

  ```python
  >>> filt=platon.filter('latest')
  >>>platon.getFilterChanges(filt.filter_id)
  [HexBytes ( '0x59c4cb22c15ed83279e288ccc94980162e7cc7c1ff9c6b4fb6d9584308727b46'), HexBytes ( '0xb205babee34ba218816d1a32e995a4c8f4ccf95d3315c6a259955f1598ed5e4d'), HexBytes ( '0xb491ef8c0cc55cc1b70e9af766ada828a5a96bbb41f6aa26b87c98dbf09ac762'), HexBytes ( '0x455ae7bee30a02210fc17ade1cec3d783ce9614f81149ea650efc27a39e495a5'), HexBytes ( '0xd8c8f327e6613dc9a638c4ad2e2e37ce511ea80d374fea91d961d3fb55ed0e3a'), HexBytes ( '0x92e85ab7340ae8f6c0da6d5fa5cab5a3ae61f7d69158b612b7caf470de4e0958'), HexBytes ( '0x612d8f92bdec45052576b62a03a5c6d5b219ad5eecf088163cc629efc506a4dc'), HexBytes ( '0xd433b552bf421ee416c31d7c9162d8f08a7580d906538a3e0156f504161c6889'), HexBytes ( '0x5f9d64faf699f6e688989bcb6133c001cd5d24315c22375c5f1935909ee5b31e'), HexBytes ( '0x70b10afd243a5f6c0992bdb80bf75974cf3b8b78c254c054e6824621d2a55a33'), HexBytes ( '0x5f631fc85544b8e04504a71e99a67f8020596221ecfbefefde98fb44f4c3cf65'), HexBytes ( '0x6012ab1a562e818e4ca3e6e1b719e21cd900ac1daaf26c87f983c75e2cddd9ab'), HexBytes ( '0x2cc3d3e257dd9af953968a75a65 3cd9cfb0f6157aca1ba3089ebfe65d32c3543 '), HexBytes (' 0x3696eea818d042c0cae606093262268ec36aa0f23904101cdb25d7c1595bbeae '), HexBytes (' 0x4825078dc7cfb3f065acd1d300a3c111b51445488862bebd44801af6272d36cd '), HexBytes (' 0x3df27825fa9e89b91f83df4769ae6477bf060c5ff078e8f1b05edee136368f4f '), HexBytes (' 0x9e7bdf9ef1ce7e66b3615fa882fa420dfefe3c93efb433ff824d6c7fa73e08ca '), HexBytes (' 0x0d8f9a5a5cd4e95a57f6183c94826861a259e631d0127f4b0f268e104bc3c92e '), HexBytes (' 0xa310dbde88c8721fad793c7f2cb594b2bec108482990d2c56e3dc427f09d21af '), HexBytes (' 0x2e944efb7d3cf8bf9c354a02b34cbc262a044b5e2fd484daad8f7b81663e4cb0 '), HexBytes (' 0x19c72519b3fcf6d74bcef061f0f6b12eabbf9cb13d482db38b94e1fb86dd4b25 '), HexBytes (' 0x435956b99ce8d0777d5d7e19e87d3277eccd757a56da6d100fb7b536ff417ded '), HexBytes (' 0xe291f184a80c1c65a44198ed8c2d35d5ef98f65dada59a0e1fc28aa21bbe69ea '), HexBytes (' 0x21b088023a06a9c85b16fcdd6bab07697905241a139d8a3efc0e0e7a9d7a00a0 '), HexBytes (' 0x6bf9d36ec461b66191ec8f026bec905a0f46a83707960987bb559d13a5186082 '), HexBytes ( '0x85aaf311fe7c2c80340f334b7f52bb0c4282341559e056e852e92135bc04e917'), HexBytes ( '0x033e7b67bd5f509de11e38cc142a70def69048f5d214ac5d15e83102a93a011d'), HexBytes ( '0x02d55d41e12ea9edd986da149e42f302719ad769eb4496872271c063a6ab3bcd'), HexBytes ( '0x3914a9fcf5be7aca72a50d59a1b7cdb18f96540dafba0de84f8297228cb9159a'), HexBytes ( '0xc45b0552883b21012431f9e76ccd5ce9e3c8550ecbbb223a1d69ebc6a354b34d'), HexBytes ( '0xbfa4324da6aafa66907586c535a2207a082063670fff102f8df19ab1a4e665d0')]
  
  ```



##### (3) platon.getFilterLogs()

  Poll the specified filter and return the corresponding log array

  transfer:

  ```
  platon.getFilterLogs(filter_id)
  ```

  parameter:

- filter_id: filter_id of the specified filter



##### (4) platon.uninstallFilter()

  Uninstall the specified filter and return the bool value of success or failure

  transfer:

  ```
  platon.getFilterLogs(filter_id)
  ```

parameter:
- filter_id: filter_id of the specified filter

Example:

```python
>>> platon.uninstallFilter(filt.filter_id)
True
```



##### (5) platon.getLogs()

  Return the history log according to the specified options.

  transfer:

  ```
  platon.getLogs(options)
  ```

  parameter:

- `options`: Object-filter object, including the following fields:    
- fromBlock-Number|String: The number of the earliest block ("latest" may be given to mean the most recent and "pending" currently mining, block). By default "latest".    
- toBlock-Number|String: The number of the latest block ("latest" may be given to mean the most recent and "pending" currently mining, block). By default "latest".    
- address-String|Array: An address or a list of addresses to only get logs from particular account(s).
- topics-Array: An array of values ​​which must each appear in the log entries. The order is important, if you want to leave topics out use null, eg [null, '0x12...']. You can also pass an array for each topic with options for that topic eg [null, ['option1','option2']]

  return value:

  An AttributeDict object whose parsed value is an array of log objects.

  The event object structure in the array is as follows:

- address-String: The source address of the event

- data-String: Contains unindexed log parameters

- topics-Array: an array containing up to 4 32-byte topics, topics 1-3 contain log index parameters

- logIndex-Number: The index position of the event in the block

- transactionIndex-Number: The index position of the transaction containing the event

- transactionHash 32 Bytes-String: The hash value of the transaction containing the event

- blockHash 32 Bytes-String: The hash value of the block containing the event, or null if it is in the pending state

- blockNumber-Number: The block number containing the event, this field is null when it is in the pending state



##### (6) functions()

  Entrance to call contract function

  transfer:

  ```python
  myContract.functions.myMethod([param1[, param2[, ...]]]).transact(options)
  ```

-  parameter:
  - `options`-Object: Options, including the following fields:
  - `from`-String (optional): The address the call “transaction” should be made from.
  - gasPrice-String (optional): The gas price in VON to use for this call “transaction”.
  - gas-Number (optional): The maximum gas provided for this call “transaction” (gas limit).


​      

##### (7) call()

  Call the method of the contract and execute the method directly in the contract without sending any transactions. Therefore, the state of the contract will not be changed.

  transfer:

  ```
  myContract.functions.myMethod([param1[, param2[, ...]]]).call()
  ```

  parameter:

- [param1[, param2[, ...]]]: parameters entered according to the data type defined in myMethod

  return value:

   The parsed value is the return value of the contract method, the Mixed type. If the contract method returns multiple values, the resolved value is an object.

  ```python
  tx_hash1 = payable.functions.setInt64(-9223372036854775808).transact(
      {
          'from':from_address,
          'gas': 1500000,
      }
  )
  print(platon.waitForTransactionReceipt(tx_hash1))
  print('get: {}'.format(
      payable.functions.getInt64().call()
  ))
  
  #Output
  get: -9223372036854775808
  ```

  

##### (8) events

  Subscribe to the specified contract event.

  transfer:

  ```
  myContract.events.MyEvent([options])
  ```

- parameter:
  - options-Object: Optional, options for deployment, including the following fields:    
  - filter-Object: Optional, filter events by index parameter. For example, {filter: {myNumber: [12,13]}} means all events where "myNumber" is 12 or 13
  - fromBlock-Number: Optional, only listen to events that occur in the block with the number specified by this option
  - topics-Array: Optional, used to manually set topics for event filters. If the filter attribute and event signature have been set, then (topic[0]) will not be set automatically

  return value:

  EventEmitter: Event generator, declares the following events:	

- "data" returns Object: Triggered when a new event is received, the parameter is the event object.
- "changed" returns Object: Triggered when the event is removed from the blockchain, the event object will be added with an additional property "removed: true".

- "error" returns Object: Triggered when an error occurs.

  The returned event object structure is as follows:

- event-String: event name.
- signature-String|Null: Event signature, if it is an anonymous event, it will be null.
- address-String: Event source address.
- returnValues-Object: Event return value, for example {myVar: 1, myVar2: '0x234...'}.
- logIndex-Number: The index position of the event in the block.
- transactionIndex-Number: the index position of the event in the transaction.
- transactionHash 32 Bytes-String: The hash value of the transaction where the event is located.
- blockHash 32 Bytes-String: The hash value of the block where the event is located, the value of the pending block is null.
- blockNumber-Number: The number of the block where the event is located, the value of the pending block is null.
- raw.data-String: This field contains unindexed log parameters.
- raw.topics-Array: Up to 4 32-byte long topic string arrays can be stored. Topics 1-3 include index parameters for events.

  Sample code:

  ```python
  greeter = platon.contract(address=tx_receipt.contractAddress, abi=abi)
  
  tx_hash = greeter.functions.setVar(100).transact(
      {
          'from':from_address,
          'gas': 1500000,
      }
  )
  
  tx_receipt = platon.waitForTransactionReceipt(tx_hash)
  print(tx_receipt)
  
  topic_param = greeter.events.MyEvent().processReceipt(tx_receipt)
  print(topic_param)
  
  #Output:
  AttributeDict({'blockHash': HexBytes('0x78fb61da83dae555c8a8a87fc3296f466afeb7f90e9a3b0ac5689e8b34435174'),'blockNumber': 2014683,'contractAddress': None,'cumulativeqqdUsed': 43148x' from [AttributeDict({'address':'lax1vc6phdxhdkmztpznv5ueduw6cae3swe40whlsn','topics': [HexBytes('0x6c2b4666ba8da5a95717621d879a77deactionf3d816709b9cbe9f'b8f3d816709b9cbe9f059'b8f0000000000000'Number00000000'00000064',0000000000000)',00000000000000 HexBytes ( '0xe36b5d2b679d5635ab6dd2b620caa50a476fa84bd93bf7b6c8de807f3a9da483'), 'transactionIndex': 0, 'blockHash': HexBytes ( '0x78fb61da83dae555c8a8a87fc3296f466afeb7f90e9a3b0ac5689e8b34435174'), 'logIndex': 0, 'removed': False})], 'logsBloom': HexBytes ( '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000020080000000000000000000000000000000000000000000000000000 000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000008000000000000000 '),' status': 1, 'to': 'lax1vc6phdxhdkmztpznv5ueduw6cae3swe40whlsn', 'transactionHash': HexBytes ( '0xe36b5d2b679d5635ab6dd2b620caa50a476fa84bd93bf7b6c8de807f3a9da483'), 'transactionIndex': 0})
  (AttributeDict({'args': AttributeDict({'_var': 100}),'event':'MyEvent','logIndex': 0,'transactionIndex': 0,'transactionHash': HexBytes('0xe36b5d2b679d5635ab6dd2b620caa483807f) 'address':'lax1vc6phdxhdkmztpznv5ueduw6cae3swe40whlsn','blockHash': HexBytes('0x78fb61da83dae555c8a8a87fc3296f466afeb7f90e9a3b0ac5689e8)34435174'), '2014683
  
  ```

 #### 7. Get hrp

```
w3 = Web3(HTTPProvider("http://localhost:6789"),chain_id = 100)
platon = PlatON(w3)
print(platon.getAddressHrp)
```



### Third part: the contract

#### 1. Contract introduction

The PlatON blockchain supports smart contracts (evm) created using the solidity language, and it also supports WebAssembly (WASM) to execute smart contracts written by users. Among them, WASM is a binary instruction set designed for stack virtual machines. WASM is designed to be available for platform compilation targets like C/C++/Rust and other high-level languages. The original design purpose is to solve the performance problem of JavaScript. WASM is a Web standard that is being promoted by W3C and is supported by browser vendors such as Google, Microsoft, and Mozilla.

For details on the introduction, creation, and compilation of evm and wasm contracts, please refer to [Platon Smart Contract](https://devdocs.platon.network/docs/zh-CN/WASM_Smart_Contract/)



#### **2**、 Contract compilation

The python sdk currently supports bin and abi formed after the evm and wasm contracts are compiled as contract data to interact with the PlatON blockchain.

**(1)** The evm contract (created in solidity language) can be compiled, deployed, and invoked using platon-truffle. For details, please refer to [solidity compiler](https://github.com/AlayaNetwork/solidity) and [platon-truffle](https://platon-truffle.readthedocs.io/en/v0.13.1/getting-started/ installation.html)
**(2)** The wasm contract (created in C/C++/Rust and other languages) can be compiled, deployed, and invoked using PlatON-CDT or platon-truffle. For details, please refer to [PlatON-CDT Compiler](https://github.com/AlayaNetwork/PlatON-CDT/tree/feature/wasm)


#### 3. SDK calls to evm contract

##### (1) Use platon-truffle to compile the evm contract locally

  Obtain bin and abi. Take the Helloworld contract as an example.

 After using platon-truffle to compile Helloworld.sol, get the abi and bytecode (bin) in the generated build/contracts/HelloWorld.json.

##### (2) Deploy Helloworld contract through python SDK

  First connect to the node via Web3

  from_address is the account address on the node

  bytecode and abi are the bin and abi after the evm contract is compiled

  ```python
  from hexbytes import HexBytes
  from client_sdk_python import Web3, HTTPProvider
  from client_sdk_python.eth import PlatON
  from platon_keys.utils import bech32,address
  from client_sdk_python.packages.eth_utils import to_checksum_address
  
  true = True
  false = False
  
  w3 = Web3(HTTPProvider("http://10.1.1.5:6789"),chain_id = 100)
  platon = PlatON(w3)
  print(w3.isConnected())
  
  from_address = "lax1yjjzvjph3tw4h2quw6mse25y492xy7fzwdtqja"
  
  bytecode = '            0160010185558215610bbd579182015b82811115610bbc578251825591602001919060010190610ba1565b5b509050610bca9190610bce565b5090565b610bf091905b80821115610bec576000816000905550600101610bd4565b5090565b9056fea265627a7a7231582003a28b4281af2c524edc05a0c071a68e9f08b99e0a7e70b37dcc181d06a48e6c64736f6c634300050d0032 '
  
  abi = [{"constant":false,"inputs":[],"name":"doWhileControl","outputs":[{"internalType":"uint256","name":"","type": "uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"doWhileControlResult" ,"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type": "function"},{"constant":false,"inputs":[],"name":"forBreakControl","outputs":[{"internalType":"uint256","name":"","type ":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":" forBreakControlResult","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type ":"function"},{"constant":false,"inputs":[],"name":"forContinueControl","outputs":[{"internalType":"uint256","name":"", "type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name" :"forContinueControlResu lt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type ":"function"},{"constant":false,"inputs":[],"name":"forControl","outputs":[{"internalType":"uint256","name":"", "type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name" :"forControlResult","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view", "type":"function"},{"constant":false,"inputs":[],"name":"forReturnControl","outputs":[{"internalType":"uint256","name":" ","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[]," name":"forReturnControlResult","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view ","type":"function"},{"constant":false,"inputs":[{"internalType":"int256","name":"age","type":"int256"}], "name":"forThreeControlControl","outputs":[],"pa yable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"forThreeControlControlResult","outputs":[{ "internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{" constant":true,"inputs":[],"name":"getForBreakControlResult","outputs":[{"internalType":"uint256","name":"","type":"uint256"}] ,"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getForContinueControlResult","outputs": [{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}, {"constant":true,"inputs":[],"name":"getForControlResult","outputs":[{"internalType":"uint256","name":"","type":"uint256" }],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getForReturnControlResult","outputs ":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"fu nction"},{"constant":true,"inputs":[],"name":"getForThreeControlControlResult","outputs":[{"internalType":"string","name":"","type" :"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getIfControlResult ","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type" :"function"},{"constant":true,"inputs":[],"name":"getdoWhileResult","outputs":[{"internalType":"uint256","name":""," type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":" uint256","name":"age","type":"uint256"}],"name":"ifControl","outputs":[],"payable":false,"stateMutability":"nonpayable", "type":"function"},{"constant":true,"inputs":[],"name":"ifControlResult","outputs":[{"internalType":"string","name":" ","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]
  
  #Output
  True
  lax1yjjzvjph3tw4h2quw6mse25y492xy7fzwdtqja
  ```

  ​ Then use the function contract_deploy(bytecode, fromAddress) to deploy the evm contract on the nodes of the PlatON blockchain by sending transactions, and return the transaction hash transactionHash.

  ​ tx_receipt is the deployment receipt obtained after platon.waitForTransactionReceipt parses the transactionHash (deployment is also a transaction, and the transaction obtains the transaction receipt through platon.waitForTransactionReceipt).

  ```python
  def contract_deploy(bytecode, fromAddress):
      bytecode = bytecode
      transactionHash = platon.sendTransaction(
          {
              "from": fromAddress,
              "gas": 1000000,
              "gasPrice": 1000000000,
              "data": bytecode,
          }
      )
      transactionHash = HexBytes(transactionHash).hex().lower()
      return transactionHash
  
  tx = contract_deploy(bytecode, from_address)
  print(tx)
  tx_receipt = platon.waitForTransactionReceipt(tx)
  print(tx_receipt)
  contractAddress = tx_receipt.contractAddress
  print(contractAddress)
  
  ```

   platon.sendTransaction (parameter)

- parameter:

    - `from` The address of the account that sent the transaction.

    -  `data` The data sent to the chain.

    - `gas` The amount of gas traded.

    - `gasPrice` fuel price.


  Need to write a reasonable value

  

  If the deployment is successful, the output results are as follows

  ```python
  
  #Output
  0x143efc88f581c4356156519cde51064222ec5a42fcb4d83400a8b11893a95074
  AttributeDict ({ 'blockHash': HexBytes ( '0xf73097d8e7b2cc385910a4af3a4dbc7588774bad3f2b6589052503b649af1525'), 'blockNumber': 305798, 'contractAddress':' lax1ws7m2tqr55h8xs7e3jg5svlyu0lk9ktpx03cke ',' cumulativeGasUsed ': 319449,' from ':' lax1yjjzvjph3tw4h2quw6mse25y492xy7fzwdtqja ',' gasUsed ': 319449,' logs ': [],' logsBloom ': HexBytes ('   '),' status': 1, 'to': None, 'transactionHash': HexBytes ( '0x143efc88f581c4356156519cde51064222ec5a42fcb4d83400a8b11893a95074'), 'transactionIndex': 0})
  lax1ws7m2tqr55h8xs7e3jg5svlyu0lk9ktpx03cke
  ```

  - among them 

    - The first line of data is the transaction result of platon.sendTransaction in the function contract_deploy.
    - The second line of data is the transaction receipt obtained by platon.waitForTransactionReceipt.
    -  The third line is the contract address where the contract is successfully deployed.

  

##### (3) Call the Helloworld contract (transaction sending)

  Based on the successful deployment of the previous contract, the transaction is sent

  First define a function SendTxn(txn)

  Contains: Sign transaction platon.account.signTransaction (signature with private key)

  ​ Send transaction platon.sendRawTransaction

  ​ Get transaction receipt platon.waitForTransactionReceipt

  ```python
  send_privatekey = "b7a7372e78160f71a1a75e03c4aa72705806a05cf14ef39c87fdee93d108588c"
  def SendTxn(txn):
      signed_txn = platon.account.signTransaction(txn,private_key=send_privatekey)
      res = platon.sendRawTransaction(signed_txn.rawTransaction).hex()
      txn_receipt = platon.waitForTransactionReceipt(res)
      print(res)
      return txn_receipt
    
  ```

  Create a contract instance contract_instance. Because it is an evm contract, the function contract is used. If it is a wasm contract, it corresponds to the function wasmcontract.

  Call method ifControl through functions, input parameter 20, and send transaction information through buildTransaction

  ```python
  contract_instance = platon.contract(address=contractAddress, abi=abi)
  
  txn = contract_instance.functions.ifControl(20).buildTransaction(
      {
          'chainId': 200,
          'nonce':platon.getTransactionCount(from_address),
          'gas': 2000000,
          'value':0,
          'gasPrice':1000000000,
      }
  )
  
  print(SendTxn(txn))
  
  result = contract_instance.functions.getIfControlResult().call()
  print(result)
  ```

parameter:

- `chainId`: chain id.

- `nonce`: serial number.

- `gas` :fuel.
- `value`: value (starting balance of new contract account).
- `gasPrice`: fuel price.

Need to write a reasonable value

 Call the method ifControl, and successfully pass the parameter 20 to the chain. Then get the corresponding information and data on the chain through the corresponding method getIfControlResult.

The output is as follows:

  ```
  #Output:
  0x16c76387cdd06ab82a4beb330b36369a5cfa22b8cf6ddfff58c72aaae4a39df9
  AttributeDict(('blockHash': HexBytes('0xbb1d1c3a7abecac9910509ed3ff2ca97cebdba1e88db0b909ffd646a86d69597'),'blockNumber': 305801,'contractAddress': None,'cumulativeGaswUsedjj25382,'from [], 'logsBloom': HexBytes ( ' '), 'status': 1, 'to': 'lax1ws7m2tqr55h8xs7e3jg5svlyu0lk9ktpx03cke', 'transactionHash': HexBytes ( '0x16c76387cdd06ab82a4beb330b36369a5cfa22b8cf6ddfff58c72aaae4a39df9'), 'transactionIndex': 0})
  ```

- among them 

  - The first line of data is the transaction result of platon.sendRawTransaction in the function SendTxn.

  - The second line of data is the method ifControl sends information to the chain, the result of the transaction.

  - The third line method getIfControlResult gets the information on the chain and the result of the transaction.



##### (4) Event call of evm contract

  The evm contract can monitor and log the detailed information of related transactions through events.

  Take the evmevent contract as an example: it adds the event type MyEvent to the method setVar.

  Greeter is the successfully deployed evm contract.

  First call setVar through functions and pass the parameters to the chain

  Then through greeter.events.MyEvent(), call the event to output the detailed log of the transaction.

  The .events method is the event api dedicated to the contract.

  ```python
  greeter = platon.contract(address=tx_receipt.contractAddress, abi=abi)
  
  tx_hash = greeter.functions.setVar(100).transact(
      {
          'from':from_address,
          'gas': 1500000,
      }
  )
  
  tx_receipt = platon.waitForTransactionReceipt(tx_hash)
  print(tx_receipt)
  
  topic_param = greeter.events.MyEvent().processReceipt(tx_receipt)
print(topic_param)
  ```

  Output after successful operation:

  ```python
  AttributeDict({'blockHash': HexBytes('0x78fb61da83dae555c8a8a87fc3296f466afeb7f90e9a3b0ac5689e8b34435174'),'blockNumber': 2014683,'contractAddress': None,'cumulativeqqdUsed': 43148x' from [AttributeDict({'address':'lax1vc6phdxhdkmztpznv5ueduw6cae3swe40whlsn','topics': [HexBytes('0x6c2b4666ba8da5a95717621d879a77deactionf3d816709b9cbe9f'b8f3d816709b9cbe9f059'b8f0000000000000'Number00000000'00000064',0000000000000)',00000000000000 HexBytes ( '0xe36b5d2b679d5635ab6dd2b620caa50a476fa84bd93bf7b6c8de807f3a9da483'), 'transactionIndex': 0, 'blockHash': HexBytes ( '0x78fb61da83dae555c8a8a87fc3296f466afeb7f90e9a3b0ac5689e8b34435174'), 'logIndex': 0, 'removed': False})], 'logsBloom': HexBytes ( '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000020080000000000000000000000000000000000000000000000000000 000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000008000000000000000 '),' status': 1, 'to': 'lax1vc6phdxhdkmztpznv5ueduw6cae3swe40whlsn', 'transactionHash': HexBytes ( '0xe36b5d2b679d5635ab6dd2b620caa50a476fa84bd93bf7b6c8de807f3a9da483'), 'transactionIndex': 0})
  (AttributeDict({'args': AttributeDict({'_var': 100}),'event':'MyEvent','logIndex': 0,'transactionIndex': 0,'transactionHash': HexBytes('0xe36b5d2b679d5635ab6dd2b620caa483807f) 'address':'lax1vc6phdxhdkmztpznv5ueduw6cae3swe40whlsn','blockHash': HexBytes('0x78fb61da83dae555c8a8a87fc3296f466afeb7f90e9a3b0ac5689e8)34435174'), '2014683

  ```

  The first line calls the function setVar, the transaction receipt after the transaction is successful.

  The second line calls the event MyEvent() to get the transaction log information.

  Among the values ​​corresponding to'args':

  '_var' is the only parameter value

  In the event of the evm contract, the basic types of data are uint, int, bool, address, bytex.

  

#### 4. SDK calls to wasm contract:



##### (1) Use PlatON-CDT to compile wasm contract locally

  Take wasmcontract.cpp as an example. After installing PlatON-CDT on this machine, enter the code in PlatON-CDT/build/bin.

  ```
  platon-cpp wasmcontract.cpp
  ```

  After successful compilation, there are two files in wasmcontract/build/contracts.

  wasmcontract.abi.json and wasmcontract.wasm, where wasmcontract.abi.json is abi data (json format), wasmcontract.wasm is bin data (binary format).

  ```python
   import binascii
   f = open('D:/wasmcontract.wasm','rb')
   contents=f.read()
   bytecode=binascii.b2a_hex(contents)
  ```

  Because what our chain recognizes is hexadecimal data, we need to use methods similar to binascii.b2a_hex to convert the binary .wasm to hexadecimal bytecode. Facilitate our identification on the chain.

##### (2) Deploy Helloworld contract (wasm type) through python SDK

  After obtaining the bin and abi of the wasm contract, deploy on the chain through Web3.

  In the code below, bytecode is the bin data of the contract, and cabi is the abi data of the contract.

  ```python
  from client_sdk_python import Web3, HTTPProvider
  from client_sdk_python.eth import PlatON
  true = True
  false = False
  
  w3 = Web3(HTTPProvider("http://10.1.1.2:6789"),chain_id = 100)
  platon = PlatON(w3)
  print(w3.isConnected())
  from_address = "lax1uqug0zq7rcxddndleq4ux2ft3tv6dqljphydrl"
  
  bytecode = '                                                                                                                                                                     '
  cabi = [{"constant":false,"input":[{"name":"input","type":"string[10]"}],"name":"setArray","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getUint32","output":"uint32","type":"Action"},{"constant":false,"input":[{"name":"input","type":"int64"}],"name":"setInt64","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getInt64","output":"int64","type":"Action"},{"constant":false,"input":[{"name":"input","type":"pair<string,int32>"}],"name":"setPair","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getPair","output":"pair<string,int32>","type":"Action"},{"anonymous":false,"input":[{"name":"topic","type":"string"},{"name":"arg1","type":"string"}],"name":"transfer","topic":1,"type":"Event"},{"anonymous":false,"input":[{"name":"topic","type":"string"},{"name":"arg1","type":"string"},{"name":"arg2","type":"uint16"}],"name":"setUint16Evt","topic":1,"type":"Event"},{"constant":false,"input":[{"name":"addr","type":"FixedHash<20>"}],"name":"setAddress","output":"void","type":"Action"},{"anonymous":false,"input":[{"name":"topic1","type":"string"},{"name":"topic2","type":"uint32"},{"name":"arg1","type":"string"},{"name":"arg2","type":"uint32"},{"name":"arg3","type":"uint32"}],"name":"setUint32Evt","topic":2,"type":"Event"},{"constant":false,"input":[],"name":"init","output":"void","type":"Action"},{"constant":false,"input":[{"name":"input","type":"uint8"}],"name":"setUint8","output":"void","type":"Action"},{"baseclass":[],"fields":[{"name":"head","type":"string"}],"name":"message","type":"struct"},{"constant":false,"input":[{"name":"msg","type":"message"}],"name":"setMessage","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getUint8","output":"uint8","type":"Action"},{"constant":false,"input":[{"name":"input","type":"uint16"}],"name":"setUint16","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getUint16","output":"uint16","type":"Action"},{"constant":false,"input":[{"name":"input","type":"uint32"}],"name":"setUint32","output":"void","type":"Action"},{"constant":false,"input":[{"name":"input","type":"uint64"}],"name":"setUint64","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getUint64","output":"uint64","type":"Action"},{"constant":false,"input":[{"name":"input","type":"string"}],"name":"setString","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getString","output":"string","type":"Action"},{"constant":false,"input":[{"name":"input","type":"bool"}],"name":"setBool","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getBool","output":"bool","type":"Action"},{"constant":false,"input":[{"name":"input","type":"int8"}],"name":"setChar","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getChar","output":"int8","type":"Action"},{"constant":true,"input":[],"name":"getMessage","output":"message","type":"Action"},{"baseclass":["message"],"fields":[{"name":"body","type":"string"},{"name":"end","type":"string"}],"name":"my_message","type":"struct"},{"constant":false,"input":[{"name":"msg","type":"my_message"}],"name":"setMyMessage","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getMyMessage","output":"my_message","type":"Action"},{"constant":false,"input":[{"name":"input","type":"int8"}],"name":"setInt8","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getSet","output":"set<string>","type":"Action"},{"constant":true,"input":[],"name":"getInt8","output":"int8","type":"Action"},{"constant":false,"input":[{"name":"input","type":"int16"}],"name":"setInt16","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getInt16","output":"int16","type":"Action"},{"constant":false,"input":[{"name":"input","type":"int32"}],"name":"setInt32","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getInt32","output":"int32","type":"Action"},{"constant":false,"input":[{"name":"vec","type":"uint16[]"}],"name":"setVector","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getVector","output":"uint16[]","type":"Action"},{"constant":false,"input":[{"name":"input","type":"map<string,string>"}],"name":"setMap","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getMap","output":"map<string,string>","type":"Action"},{"constant":false,"input":[{"name":"msg","type":"message"},{"name":"input1","type":"int32"},{"name":"input2","type":"bool"}],"name":"testMultiParams","output":"void","type":"Action"},{"constant":false,"input":[{"name":"input","type":"uint8[]"}],"name":"setBytes","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getBytes","output":"uint8[]","type":"Action"},{"constant":true,"input":[],"name":"getArray","output":"string[10]","type":"Action"},{"constant":false,"input":[{"name":"input","type":"set<string>"}],"name":"setSet","output":"void","type":"Action"},{"constant":false,"input":[{"name":"input","type":"FixedHash<256>"}],"name":"setFixedHash","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getFixedHash","output":"FixedHash<256>","type":"Action"},{"constant":false,"input":[{"name":"input","type":"list<string>"}],"name":"setList","output":"void","type":"Action"},{"constant":true,"input":[],"name":"getList","output":"list<string>","type":"Action"},{"constant":true,"input":[],"name":"getAddress","output":"FixedHash<20>","type":"Action"}]
  
  ```

  The wasm type contract creates a contract instance through platon.wasmcontract

  Call the method .constructor() on the instance to construct the contract, and send the transaction to the chain through transact

```python
  # Instantiate and deploy contract
Payable = platon.wasmcontract(abi=cabi, bytecode=bytecode,vmtype=1)
  
tx_hash = Payable.constructor().transact(
      {
          'from':from_address,
          'gas': 1500000,
      }
  )
  
  # Wait for the transaction to be mined, and get the transaction receipt
  tx_receipt = platon.waitForTransactionReceipt(tx_hash)
  print(tx_receipt)
```

  Among them, tx_receipt is the transaction receipt of the deployment contract

  After the deployment is successful, the output is as follows

```
  #Output
AttributeDict ({ 'blockHash': HexBytes ( '0x7a193be2cf86aedcf844c0478c6f64d226affb55779bad1b2056c7e70e8158d6'), 'blockNumber': 2012981, 'contractAddress':' lax15sh4rpuqr4fvzs4cyj9uea54r5tax7kljqqszk ',' cumulativeGasUsed ': 1233168,' from ':' lax1uqug0zq7rcxddndleq4ux2ft3tv6dqljphydrl ',' gasUsed ': 1233168,' logs ': [],' logsBloom ': HexBytes ('   '),' status': 1, 'to': None, 'transactionHash': HexBytes ( '0x717a82ea0ef116e271fb02dbb7d456fe9dd41a2dbd07cac81d079e375b5dade1'), 'transactionIndex': 0} )
  
```

##### (3) Send transaction to Helloworld contract (wasm contract)

  ​ Based on the successful deployment of the previous contract, call the method in the contract.

  ​ payable is an instance after the contract is successfully deployed

  ​ By calling the function setBool, the parameter false is sent to the chain (send transaction)

  ```python
  payable = platon.wasmcontract(address=tx_receipt.contractAddress, abi=cabi,vmtype=1)
  
  tx_hash0 = payable.functions.setBool(false).transact(
      {
          'from':from_address,
          'gas': 1500000,
      }
  )
  print(platon.waitForTransactionReceipt(tx_hash0))
  print('get: {}'.format(
      payable.functions.getBool().call()
  ))
  ```

  payable.functions.getBool().call(), which means that the corresponding information on the chain is obtained through the function getBool (according to the definition of this contract, the parameters uploaded by setBool are obtained).

  After successful operation, the results are as follows:

  ```python
  #Output
  AttributeDict({'blockHash': HexBytes('0x9bcadf4db5d74789901b2176cb7dad3191d2425b61f261966e932f6606d13041'),'blockNumber': 2018575,'contractAddress': None,'cumulativeq [], 'logsBloom': HexBytes ( ' '), 'status': 1, 'to': 'lax1c5h59flven2hzyrylh2tsmn59r5ucms95n5ugc', 'transactionHash': HexBytes ( '0x4c724e7d1833ade363f51f611293682771318e3c86b533f5a78b580c812eb009'), 'transactionIndex': 0})
  get: False
  ```

##### (4) Event call of wasm contract

  Events in the wasm contract are generally written in the function of the contract.

  Take the wasmcontract contract as an example, the method setUint32 contains the event setUint32Evt, and setUint32Evt can be used to monitor and log the transaction results of setUint32.

  Greeter is an example of a successfully deployed wasm type contract

  tx_hash is a transaction instance of function setUint32 passing parameters

  ```python
  greeter = platon.wasmcontract(address=tx_receipt.contractAddress, abi=abi,vmtype=1)
  tx_hash = greeter.functions.setUint32(1000).transact(
      {
          'from': from_address,
          'gas': 1500000,
      }
  )
  
  tx_receipt = platon.waitForTransactionReceipt(tx_hash)
  print(tx_receipt)
  
  topic_param = greeter.events.setUint32Evt().processReceipt(tx_receipt)
print(topic_param)
  ```

  topic_param is the result of the event setUint32Evt call

  The output after successful operation is as follows:

  ```python
(AttributeDict(('args': AttributeDict(('topic1':'topic1','arg1':'data1','arg2': 1000,'arg3': 1000}),'event':'setUint32Evt', ' logIndex ': 0,' transactionIndex ': 0,' transactionHash ': HexBytes (' 0xabac50c6a9d443d9f89065775f0f3d56ddeabd2f2a5e0e1f36d00db703b14d8b '),' address': 'lax1sgsp74pce2vkgwqjd3rzmt55p70psmq7qvnqwn', 'blockHash': HexBytes ( '0x78f15fbacbc745dfd5b35b596d28b61ae2987b6ff9050dc39c716f383e505899'), 'blockNumber': 1477774}),)
  ```

  Among the values ​​​​corresponding to'args':

  'topic1' is the topic value,'arg1','arg2', and'arg3' are the three parameter values ​​defined in the event.



### Four part: Ppos

#### Special note

- node_id
  - When the node_id parameter needs to be passed in each api , '0x' should be removed.

#### 1.staking

```python
from client_sdk_python import Web3, HTTPProvider
from client_sdk_python.ppos import Ppos
w3 = Web3(HTTPProvider("http://localhost:6789"),chain_id = 100)
ppos = Ppos(w3)
```

##### Initiate a pledge

Calling method

```
ppos.createStaking(benifit_address, node_id, external_id, node_name, website, details, amount,program_version,program_version_sign, bls_pubkey, bls_proof, pri_key, reward_per, typ=2, transaction_cfg=None)
```

Parameter Description

- **typ**: Indicates whether the account free amount or the account's lock amount is used for staking, 0: free amount; 1: lock amount;2: Give priority to lock amount, use free amount provided that staking amount over lock amount.

- **benifit_address**: Income account for accepting block rewards and staking rewards.

- **node_id**: The idled node Id (also called the candidate's node Id).

- **external_id**: External Id (with length limit, Id for the third party to pull the node description).

- **node_name**: The name of the staking node (with a length limit indicating the name of the node).

- **website**: The third-party home page of the node (with a length limit indicating the home page of the node).

- **details**: Description of the node (with a length limit indicating the description of the node).

- **amount**: staking von (unit:von, 1LAT = 10\*\*18 von).

- **program_version**: The real version of the program, admin_getProgramVersion.

- **program_version_sign**: The real version of the program is signed, admin_getProgramVersion.

- **bls_pubkey**: Bls public key.

- **bls_proof**: Proof of bls, obtained by pulling the proof interface, admin_getSchnorrNIZKProve.

- **pri_key**: Private key for transaction.

- **reward_per**: Proportion of the reward share obtained from the commission, using BasePoint 1BP = 0.01%.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Modify pledge information

Calling method

```
ppos.editCandidate(benifit_address, node_id, external_id, node_name, website, details, pri_key, reward_per, transaction_cfg=None)
```

Parameter Description

- **benifit_address**: Income account for accepting block rewards and staking rewards.

- **node_id**: The idled node Id (also called the candidate's node Id).

- **external_id**: External Id (with length limit, Id for the third party to pull the node description).

- **node_name**: The name of the staking node (with a length limit indicating the name of the node).

- **website**: The third-party home page of the node (with a length limit indicating the home page of the node).

- **details**: Description of the node (with a length limit indicating the description of the node).

- **pri_key**: Private key for transaction.

- **reward_per**: Proportion of the reward share obtained from the commission, using BasePoint 1BP = 0.01%.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Increase stake

Calling method

```
ppos.increaseStaking(node_id, amount, pri_key, typ=2, transaction_cfg=None)
```

Parameter Description

- **typ**: Indicates whether the account free amount or the account's lock amount is used for staking, 0: free amount; 1: lock amount;2: Give priority to lock amount, use free amount provided that staking amount over lock amount.

- **node_id**: The idled node Id (also called the candidate's node Id).

- **amount**: staking von (unit:von, 1LAT = 10\*\*18 von).

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration..
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Cancel the pledge (initiate all cancellation at one time, and arrive at the account multiple times)

Calling method

```
ppos.withdrewStaking(node_id, pri_key, transaction_cfg=None)
```

Parameter Description

- **node_id**: The idled node Id (also called the candidate's node Id).

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

#### 2 .delegate

##### Initiate a delegation

Calling method

```
ppos.delegate(typ, node_id, amount, pri_key, transaction_cfg=None)
```

Parameter Description

- **typ**: Indicates whether the account free amount or the account's lock amount is used for delegate, 0: free amount; 1: lock amount.

- **node_id**: The idled node Id (also called the candidate's node Id).

- **amount**: Amount of delegate (unit:von, 1LAT = 10\*\*18 von).

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Shareholding reduction/revocation commission

Calling method

```
ppos.withdrewDelegate(staking_blocknum, node_id, amount, pri_key, transaction_cfg=None)
```

Parameter Description

- **staking_blocknum**: A unique indication of a pledge of a node.

- **node_id**: The idled node Id (also called the candidate's node Id).

- **amount**: The amount of the entrusted reduction (unit:von, 1LAT = 10\*\*18 von).

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Withdrawing delegated rewards

Calling method

```
ppos.withdrawDelegateReward(pri_key, transaction_cfg=None)
```

Parameter Description

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

#### 3.query

##### Query the validator queue of the current settlement cycle

Calling method

```
ppos.getVerifierList(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the list of validators in the current consensus cycle

Calling method

```
ppos.getValidatorList(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the list of all real-time candidates

Calling method

```
ppos.getCandidateList(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the NodeID and pledge Id of the node entrusted by the current account address

Calling method

```
ppos.getRelatedListByDelAddr(del_addr, from_address=None)
```

Parameter Description

- **del_addr**: Client's account address.
- **from_address**: Used to call the rpc call method.

##### Query the current delegation information of a single node

Calling method

```
ppos.getDelegateInfo(staking_blocknum, del_address, node_id, from_address=None)
```

Parameter Description

- **staking_blocknum**: Block height at the time of staking.
- **del_address**: Client's account address.
- **node_id**: Verifier's node ID.
- **from_address**: Used to call the rpc call method.

##### Query the pledge information of the current node

Calling method

```
ppos.getCandidateInfo(node_id, from_address=None)
```

Parameter Description

- **node_id**: Verifier's node ID.
- **from_address**: Used to call the rpc call method.

##### Query the block reward of the current settlement cycle

Calling method

```
ppos.getPackageReward(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the pledge reward of the current settlement cycle

Calling method

```
ppos.getStakingReward(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the average time of packing blocks

Calling method

```
ppos.getAvgPackTime(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### The query account has not withdrawn commission rewards at each node.

Calling method

```
ppos.getDelegateReward(address, node_ids=[])
```

Parameter Description

- **address**:account address to be queried.
- **node_ids**:the string array of the node id to be queried, if it is empty, query all nodes delegated by the account.

#### 4. Double sign

##### Report double sign

Calling method

```
ppos.reportDuplicateSign(typ, data, pri_key, transaction_cfg=None)
```

Parameter Description

- **typ**: Represents duplicate sign type, 1:prepareBlock, 2: prepareVote, 3:viewChange.

- **data**: Json value of single evidence, format reference RPC interface Evidences.

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Query whether the node has been reported too much signature

Calling method

```
ppos.checkDuplicateSign(typ, node_id, block_number, from_address=None)
```

Parameter Description

- **typ**: Represents double sign type, 1:prepareBlock, 2: prepareVote, 3:viewChange.
- **check_address**: Reported node address.
- **block_number**: Duplicate-signed block height.
- **from_address**: Used to call the rpc call method.

#### 5. Lock position

##### Create a hedging plan

Calling method

```
ppos.createRestrictingPlan(account, plan, pri_key, transaction_cfg=None)
```

Parameter Description

- **account**: Locked account release account.

- **plan**:
  An is a list of `RestrictingPlan` types (array), and `RestrictingPlan` is defined as follows:
  
  ~~~
  type RestrictingPlan struct {
  Epoch uint64
  Amount *big.Int
  }
  ~~~
  
  - where Epoch: represents a multiple of the billing period.
    The product of the number of blocks per billing cycle indicates that the locked fund
    s are released at the target block height. Epoch * The number of blocks per cycle is
    at least greater than the maximum irreversible block height.
  - Amount: indicates the amount to be released on the target block.
  
- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Get lock information

Calling method

```
ppos.getRestrictingInfo(account, from_address=None)
```

Parameter Description

- **account**: Locked account release account.
- **from_address**: Used to call the rpc call method.

#### 6. Governance

```python
from client_sdk_python import Web3, HTTPProvider
from client_sdk_python.pip import Pip
w3 = Web3(HTTPProvider("http://localhost:6789"),chain_id = 100)
pip = Pip(w3)
```

##### Text proposal

Calling method

```
pip.submitText(verifier, pip_id, pri_key, transaction_cfg=None)
```

Parameter Description

- **verifier**: The certified submitting the proposal.

- **pip_id**: PIPID.

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Upgrade proposal

Calling method

```
pip.submitVersion(verifier, pip_id, new_version, end_voting_rounds, pri_key, transaction_cfg=None)
```

Parameter Description

- **verifier**: The certified submitting the proposal.

- **pip_id**: PIPID.

- **new_version**: upgraded version.

- **end_voting_rounds**: The number of voting consensus rounds.
  Explanation: Assume that the transaction submitted by the proposal is rounded when the consensus round
  number of the package is packed into the block, then the proposal voting block is high,
  which is the 230th block height of the round of the round1 + endVotingRounds
  (assuming a consensus round out of block 250, ppos The list is 20 blocks high in advance,
  250, 20 are configurable), where 0 <endVotingRounds <= 4840 (about 2 weeks, the actual discussion
  can be calculated according to the configuration), and is an integer).
  
- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Parameter proposal

Calling method

```
pip.submitParam(verifier, pip_id, module, name, new_value, pri_key, transaction_cfg=None)
```

Parameter Description

- **verifier**: The certified submitting the proposal.

- **pip_id**: PIPID.

- **module**: parameter module.

- **name**: parameter name.

- **new_value**: New parameter value.

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Delete proposal

Calling method

```
pip.submitCancel(verifier, pip_id, end_voting_rounds, tobe_canceled_proposal_id, pri_key, transaction_cfg=None)
```

Parameter Description

- **verifier**: The certified submitting the proposal.

- **pip_id**: PIPID.

- **end_voting_rounds**:
  The number of voting consensus rounds. Refer to the instructions for submitting the upgrade proposal.
  At the same time, the value of this parameter in this interface.
  cannot be greater than the value in the corresponding upgrade proposal.
  
- **tobe_canceled_proposal_id**: Upgrade proposal ID to be cancelled.

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

Calling method

```
pip.vote(verifier, proposal_id, option, program_version, version_sign, pri_key, transaction_cfg=None)
```

Parameter Description

- **verifier**: The certified submitting the proposal.

- **proposal_id**: Proposal ID.

- **option**: Voting option.

- **program_version**: Node code version, obtained by rpc getProgramVersion interface.

- **version_sign**: Code version signature, obtained by rpc getProgramVersion interface.

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Version Statement

Calling method

```
pip.declareVersion(active_node, program_version, version_sign, pri_key, transaction_cfg=None)
```

Parameter Description

- **active_node**: The declared node can only be a verifier/candidate.

- **program_version**: The declared version, obtained by rpc's getProgramVersion interface.

- **version_sign**: The signed version signature, obtained by rpc's getProgramVersion interface.

- **pri_key**: Private key for transaction.

- **transaction_cfg**: Transaction basic configuration.
  
  ~~~
  type: 
  	dict
  example:
      cfg = {
           "gas":100000000,
           "gasPrice":2000000000000,
           "nonce":1,
       }
  ~~~
  
  

##### Query proposal

Calling method

```
pip.getProposal(proposal_id, from_address=None)
```

Parameter Description

- **proposal_id**: proposal id.
- **from_address**: Used to call the rpc call method.

##### Query proposal results

Calling method

```
pip.getTallyResult(proposal_id, from_address=None)
```

Parameter Description

- **proposal_id**: proposal id.
- **from_address**: Used to call the rpc call method.

##### Query the cumulative number of votes available for a proposal

Calling method

```
pip.getAccuVerifiersCount(proposal_id, block_hash, from_address=None)
```

Parameter Description

- **proposal_id**: proposal id.
- **block_hash**: block hash.
- **from_address**: Used to call the rpc call method.

##### Query the list of proposals

Calling method

```python
pip.listProposal(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the effective version of the node's chain

Calling method

```python
pip.getActiveVersion(from_address=None)
```

Parameter Description

- **from_address**: Used to call the rpc call method.

##### Query the governance parameter value of the current block height

Calling method

```python
pip.getGovernParamValue(module, name, from_address=None)
```

Parameter Description

- **module**: Parameter module.
- **name**: parameter name.
- **from_address**:Used to call the rpc call method.

##### Query the governance parameter list

Calling method

```python
pip.listGovernParam(self, module=None, from_address=None)
```

Parameter Description

- module:Parameter module.
- from_address: Used to call the rpc call method.
