Skip to main content

Python SDK for CKB

Project description

Python SDK for CKB

Python CKB is an experimental project that aims to provide human-friendly interfaces for common CKB operations. Note that Python CKB is not a complete SDK, but only implements the CKB functions that I am interested in.

Features:

  • No third-party dependencies. All code is visible.
  • Incredibly simple.

Installation

$ python -m pip install pyckb
# or
$ git clone https://github.com/mohanson/pyckb
$ cd pyckb
$ python -m pip install --editable . --config-settings editable_mode=strict

Usage

By default, pyckb is configured on the develop. To switch networks, see ckb.config.

example/addr.py

Calculate address from private key in secp256k1 lock.

$ python example/addr.py --prikey 0x0000000000000000000000000000000000000000000000000000000000000001

# ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4z78ng4yutl5u6xsv27ht6q08mhujf8s2r0n40

example/capacity.py

Get the capacity by an address.

$ python example/capacity.py --addr ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4z78ng4yutl5u6xsv27ht6q08mhujf8s2r0n40

# 3523312.39054609

example/deploy.py

Deploy a script to the chain.

$ python example/deploy.py --prikey 0x0000000000000000000000000000000000000000000000000000000000000001 --file LICENSE

# script.code_hash = 0x1a124d54d4f37713b8f17fc12142ede488906d4290fbb178d7aad214977814ee
# script.hash_type = 2(data1)
# out_point.hash   = 0x418f60d67ff3e9841a3091c55cb4eb50837602582495931c372fff99f3107f38
# out_point.index  = 0

example/faucet.py

One faucet to send 300000 CKB to any ckb addresses. Note this only takes effect on the testnet.

$ python example/faucet.py --addr ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4z78ng4yutl5u6xsv27ht6q08mhujf8s2r0n40

example/redeem.py

Attempt to withdraw all funds from Dao. When running the test case of pyckb by pytest -v, a part of ckb will be locked in Dao. Use this script to recover this part of the funds.

$ python example/redeem.py --prikey 0x0000000000000000000000000000000000000000000000000000000000000001

example/txdump.py

Dump full transaction data for ckb-debugger to use.

$ python example/txdump.py --net testnet --hash 0x123b09a89e65cc9c375dab739c9c921f7067d0b205e563135bb5a1221f8948d9

Test

$ wget https://github.com/nervosnetwork/ckb/releases/download/v0.115.0/ckb_v0.115.0_x86_64-unknown-linux-gnu.tar.gz
$ tar -zxvf ckb_v0.115.0_x86_64-unknown-linux-gnu.tar.gz
$ cd ckb_v0.115.0_x86_64-unknown-linux-gnu/

$ ckb init --chain dev --ba-arg 0x75178f34549c5fe9cd1a0c57aebd01e7ddf9249e --ba-message 0xabcd
$ ckb run --indexer
$ ckb miner

$ pytest -v

License

MIT

Project details


Download files

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

Source Distribution

pyckb-0.1.8.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyckb-0.1.8-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file pyckb-0.1.8.tar.gz.

File metadata

  • Download URL: pyckb-0.1.8.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyckb-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7c83e1b0a5f8c21709db2ac566fc3a616ca2b9fb047272e1af1fe6830f74c9e1
MD5 1f93c3f73863d365b402f885121c3d71
BLAKE2b-256 34d91e6e6e0c0b2b699b8f18b563b9c08c37c2af6c551c4f075e01ce2350a883

See more details on using hashes here.

File details

Details for the file pyckb-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pyckb-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyckb-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5689a69d2a3d0dcdf5de1715714e689d45636fd57fcf4ddd3cfc06ea3822af1d
MD5 e65385db7e0bd87736c388a5c6a04ceb
BLAKE2b-256 6484a1896bd7820c38db1a1bd2af03e9a78a9df8e07b28f9aa3065f4c7d31c4c

See more details on using hashes here.

Supported by

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