In3 client for python
Project description
IN3 Python Client
This is a IN3 implementation for python
Quickstart
First you should install IN3 Client for python using pip.
Installing IN3 Client
$ pip install in3py
Creating a new instance of IN3 Client (Default)
# this is a new instance with a default configuration
from in3py.client.in3_client import In3Client
in3_client = In3Client() #default in3 client
block_number = in3_client.eth.block_number()
print(block_number) # Mainnet's block's number
Creating a new instance by chain definition
from in3py.client.in3_client import In3Client
from in3py.client.in3_client import IN3Config
from in3py.model.in3_model import ChainsDefinitions
kovan = IN3Config()
kovan.chainId = ChainsDefinitions.KOVAN.value
in3_client = In3Client(in3_config=kovan)
in3_client.eth.block_number() # Kovan's block's number
Creating a new instance by "string" chainId
from in3py.client.in3_client import In3Client
from in3py.client.in3_client import IN3Config
kovan = IN3Config()
kovan.chainId= "0x2a"
in3_client = In3Client(in3_config=kovan)
in3_client.eth.block_number() # Kovan's block's number
Types
IN3 has some types to help you to handle all data.
IN3Number
from in3py.model.in3_model import IN3Number
number_str = IN3Number("0x2a")
number_int = IN3Number(42)
number_int.to_hex() == number_str.to_hex() # true
number_int.to_int() == number_str.to_int() # true
print(number_str) # 0x2a
Address
In3 Address type with validations (size and checksum)
from in3py.model.in3_model import Address
address = Address("0x9E52Ee6Acd6E7F55e860844d487556f8Cbe2BAEE", skip_validation=True)
print(address) # 0x9E52Ee6Acd6E7F55e860844d487556f8Cbe2BAEE
# without the last 'E'
address = Address("0x9E52Ee6Acd6E7F55e860844d487556f8Cbe2BAE")
# raise AddressFormatException: The address don't have enough size as needed.
# with the last 'E' but in lowercase
address = Address("0x9E52Ee6Acd6E7F55e860844d487556f8Cbe2BAEe")
# raise AddressFormatException: The Address it's not in a correct checksum.
Hash
In3 Hash type with validation (size)
from in3py.model.in3_model import Hash
hash = Hash("0x939a89debdd112ea48dc15cf491383cdfb16a5415cecef2cb396f58d8dd8d760")
print(hash) # 0x939a89debdd112ea48dc15cf491383cdfb16a5415cecef2cb396f58d8dd8d760
Hash("0x939a89debdd112ea48dc15cf49")
# raise: HashFormatException: Hash size is not a proper size of 32 bytes
Modules
Currently we have two modules,
- In3
- Ethereum
Other modules will be added soon.
Organization
All modules are inside a client instance.
from in3py.client.in3_client import In3Client
in3_client = In3Client()
in3_client.eth # ethereum module
in3_client.in3 # in3 module
Ethereum module
You can call ethereum functions using our client
- Assuming that you have the In3 Client setted correctly as we did before, we can call these functions.
The eth module is responsible to call all ethereum functions using our client to make the things easier.
gas_price
Returns the current price per gas in wei.
from in3py.client.in3_client import In3Client
in3_client= In3Client()
in3_client.eth.gas_price()
block_number
Returns the number of most recent block.
from in3py.client.in3_client import In3Client
in3_client= In3Client()
block_number = in3_client.eth.block_number()
block_number.to_int()
block_number.to_hex()
get_balance
Returns the balance of the account of given address.
address = '0xc94770007dda54cF92009BFF0dE90c06F603a09f'
in3.eth.get_balance(address, EnumsBlockStatus.LATEST)
getTransactionCount
Returns the number of transactions sent from an address.
from src.domain.bytes_types import Bytes20
address = Bytes20('0xc94770007dda54cF92009BFF0dE90c06F603a09f')
number = eth.get_transaction_count(address,EnumsBlockStatus.LATEST)
send_transaction
Creates new message call transaction or a contract creation, if the data field contains code.
from src.dto.transaction_dto import TransactionDTO
transactionDTO = TransactionDTO(From="0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to="0xd46e8dd67c5d32be8058bb8eb970870f07244567",
data="0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
gas="0x76c0",
gasPrice="0x9184e72a000",
value="0x9184e72a"
)
eth.send_transaction(transactionDTO)
get_block_by_hash
Returns information about a block by hash.
from src.domain.bytes_types import Bytes32
hash = Bytes32('0xdcded60b27fc1fc3987e9416cb3dd81159552426ab6e027a308ea94985a7f258')
eth.get_block_by_hash(hash,False)
get_block_by_number
Returns information about a block by block number.
from src.domain.in3_number import In3Number
num = In3Number(0x6a5c56)
eth.get_block_by_number(num, full=False)
get_transaction_by_hash
Returns information about a transaction by block hash and transaction index position.
eth = self.get_in3_core()
address = Bytes32('0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b')
eth.get_transaction_by_hash(address)
eth_getTransactionByBlockHashAndIndex
Returns information about a transaction by block hash and transaction index position.
block_hash = Bytes32('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331')
num = In3Number(0x0)
eth.get_transaction_by_block_hash_and_index(block_hash, num)
eth_getTransactionByBlockNumberAndIndex
Returns information about a transaction by block number and transaction index position.
number = In3Number(0x29c)
index = In3Number(0x0)
eth.get_transaction_by_block_number_and_index(number, index)
get_transaction_receipt
Returns the receipt of a transaction by transaction hash.
eth.get_transaction_receipt(Bytes32('0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'))
pending_transactions
Returns the pending transactions list.
eth.pending_transactions()
eth_getUncleByBlockHashAndIndex
Returns information about a uncle of a block by hash and uncle index position.
hash = Bytes32('0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b')
index= In3Number(0x0)
number = eth.get_uncle_by_block_hash_and_index(hash, index)
get_uncle_by_block_number_and_index
Returns information about a uncle of a block by number and uncle index position.
number = In3Number(0x29c)
index = In3Number(0x0)
eth.get_uncle_by_block_number_and_index(number, index)
eth_sendRawTransaction
TODO
eth_call
TODO
eth_estimateGas
TODO
eth_getBlockTransactionCountByHash
Returns the number of transactions in a block from a block matching the given block hash.
Bytes32('0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238')
eth.get_block_transaction_count_by_hash(hash)
eth_getBlockTransactionCountByNumber
Returns the number of transactions in a block matching the given block number.
eth.get_block_transaction_count_by_number(EnumsBlockStatus.LATEST)
eth_getUncleCountByBlockHash
Returns the number of uncles in a block from a block matching the given block hash.
hash = Bytes32('0xc94770007dda54cF92009BFF0dE90c06F603a09f')
eth.get_uncle_count_by_block_hash(hash)
eth_getUncleCountByBlockNumber
Returns the number of uncles in a block from a block matching the given block number.
eth.get_uncle_count_by_block_number(EnumsBlockStatus.LATEST)
eth_sign
The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).
By adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.
Note the address to sign with must be unlocked.
address = Bytes20('0x9b2055d370f73ec7d8a03e965129118dc8f5bf83')
message = '0xdeadbeaf'
eth.sign(address,message)
get_storage_at
Returns the value from a storage position at a given address.
address = Bytes20('0x295a70b2de5e3953354a6a8344e616ed314d7251')
position = In3Number(0x0)
storage = eth.get_storage_at(address, position, EnumsBlockStatus.LATEST)
get_code
address = Bytes20('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b')
number = In3Number(0x0)
code = eth.get_code(address, number)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.