neb.py
neb.py is the Nebulas compatible Python API. Users can sign/send transactions and deploy/call smart contract with it.
Installation
You can install this library via pip:
pip install neb-py
Usage
please refer to examples to learn how to use neb.py.
Account
from nebpysdk.src.account.Account import Account
# generate a new account
account = Account()
account2 = Account.new_account() #another way to create account
priv_key = "6c41a31b4e689e1441c930ce4c34b74cc037bd5e68bbd6878adb2facf62aa7f3"
account3 = Account(priv_key) #create account with given priv_key
# export account
account_json = account.to_key(bytes("passphrase".encode()))
print(account_json)
# load account
account = Account.from_key(account_json, bytes("passphrase".encode()))
print(account.get_address_str())
print(account.get_private_key())
print(account.get_public_key())
API
from nebpysdk.src.client.Neb import Neb
import json
neb = Neb("https://testnet.nebulas.io")
# getNebState
print(neb.api.getNebState().text)
# latestIrreversibleBlock
print(neb.api.latestIrreversibleBlock().text)
Transaction
from nebpysdk.src.account.Account import Account
from nebpysdk.src.core.Address import Address
from nebpysdk.src.core.Transaction import Transaction
from nebpysdk.src.core.TransactionBinaryPayload import TransactionBinaryPayload
from nebpysdk.src.core.TransactionCallPayload import TransactionCallPayload
from nebpysdk.src.client.Neb import Neb
import json
neb = Neb("https://testnet.nebulas.io")
keyJson = '{"version":4,"id":"814745d0-9200-42bd-a4df-557b2d7e1d8b","address":"n1H2Yb5Q6ZfKvs61htVSV4b1U2gr2GA9vo6","crypto":{"ciphertext":"fb831107ce71ed9064fca0de8d514d7b2ba0aa03aa4fa6302d09fdfdfad23a18","cipherparams":{"iv":"fb65caf32f4dbb2593e36b02c07b8484"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dddc4f9b3e2079b5cc65d82d4f9ecf27da6ec86770cb627a19bc76d094bf9472","n":4096,"r":8,"p":1},"mac":"1a66d8e18d10404440d2762c0d59d0ce9e12a4bbdfc03323736a435a0761ee23","machash":"sha3256"}}';
password = 'passphrase'
# prepare from&to addr
from_account = Account.from_key(keyJson, bytes(password.encode()))
from_addr = from_account.get_address_obj()
to_addr = Address.parse_from_string("n1JmhE82GNjdZPNZr6dgUuSfzy2WRwmD9zy")
print("from_addr", from_addr.string())
print("to_addr ", to_addr.string())
# prepare transaction, get nonce first
resp = neb.api.getAccountState(from_addr.string()).text
print(resp)
resp_json = json.loads(resp)
print(resp_json)
nonce = int(resp_json['result']['nonce'])
chain_id = 1001
# PayloadType
payload_type = Transaction.PayloadType("binary")
# payload
payload = TransactionBinaryPayload("test").to_bytes()
# gasPrice
gas_price = 1000000
# gasLimit
gas_limit = 20000
# binary transaction example
tx = Transaction(chain_id, from_account, to_addr, 0, nonce + 1, payload_type, payload, gas_price, gas_limit)
tx.calculate_hash()
tx.sign_hash()
print(neb.api.sendRawTransaction(tx.to_proto()).text)
# call type
to_addr = Address.parse_from_string("n1oXdmwuo5jJRExnZR5rbceMEyzRsPeALgm")
func = "get"
arg = '["nebulas"]'
payload = TransactionCallPayload(func, arg).to_bytes()
payload_type = Transaction.PayloadType("call")
tx = Transaction(chain_id, from_account, to_addr, 0, nonce + 1, payload_type, payload, gas_price, gas_limit)
tx.calculate_hash()
tx.sign_hash()
print(neb.api.sendRawTransaction(tx.to_proto()).text)
Join in!
We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.
Please report bugs via the github issue
Metadata
Release files for neb-py 0.4.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neb-py-0.4.3.1.tar.gz | 208.9 kB | Without provenance | Details for neb-py-0.4.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neb_py-0.4.3.1-py3-none-any.whl | Python 3 | none | any | Details for neb_py-0.4.3.1-py3-none-any.whl |
Total release size: 482.0 kB
Release files / neb-py-0.4.3.1.tar.gz
| Download URL | neb-py-0.4.3.1.tar.gz |
|---|---|
| Size | 208.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b9390dd7cef5cce776aceda6638ac68354943738748b3e3a72fd961e3b303b2
|
|
BLAKE2b-256 checksum How to use checksums |
b28cc462492da59a17ad8a7dbf4089b13cee51c9187904a5806548880e0a4a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
|
Release files / neb_py-0.4.3.1-py3-none-any.whl
| Download URL | neb_py-0.4.3.1-py3-none-any.whl |
|---|---|
| Size | 273.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ebc6e78c86ab3459f5eef5929e6a80b600841c3884913e107eb93fd0e9c0f66d
|
|
BLAKE2b-256 checksum How to use checksums |
f83c6d4dd44855e78f84d10cd00e01cf8314aacb063ef4a689c3d6f9e36ec347
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
|
Security for neb-py 0.4.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.