Skip to main content

pyckb: nervos ckb library for humans

Project description

Pyckb: Nervos CKB Library For Humans

Pyckb is a project that aims to provide human-friendly interfaces for common ckb operations. Using pyckb, you can easily and happily complete everything you want to do on ckb.

Features:

  • No third-party dependencies, everything is visible.
  • Incredibly simple, even a cat knows how to use it.

Installation

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

Usage

By default, pyckb is configured on the develop. To switch networks, use pyckb.config.current = pyckb.config.mainnet.

example/addr.py

Calculate address from private key in secp256k1 lock.

$ python example/addr.py --prikey 1

# 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 1 --file LICENSE

# script.code_hash = 1a124d54d4f37713b8f17fc12142ede488906d4290fbb178d7aad214977814ee
# script.hash_type = 2(data1)
# out_point.hash   = 418f60d67ff3e9841a3091c55cb4eb50837602582495931c372fff99f3107f38
# 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 1

example/transfer.py

Transfer ckb to another account. If value is 0, then all assets will be transferred.

$ python example/transfer.py --prikey 1 --to ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrcaufs8qeu8wvvy0myyedek4vqad9qeq3gc4cf --value 100

example/txdump.py

Dump full transaction data for ckb-debugger to use.

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

example/unittest.py

Pyckb provides a unit testing framework to help script developers test their scripts. To use this framework, you need to install ckb-debugger first. This example tests an always success script.

$ python example/unittest.py

# Run result: 0
# All cycles: 539

Test

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

$ ckb init --chain dev --ba-arg 0x75178f34549c5fe9cd1a0c57aebd01e7ddf9249e
$ 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-1.2.4.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

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

pyckb-1.2.4-py2.py3-none-any.whl (24.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: pyckb-1.2.4.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pyckb-1.2.4.tar.gz
Algorithm Hash digest
SHA256 d0091ef8ca4a28e6f16a9c7fd2bf9203ed0399c9c73dcb0d89a60bdc76d00a44
MD5 9b4a600397a24ff2cc4e6997cd15df1f
BLAKE2b-256 467cf56921f42ca817e2ee3842cfd0fff4d7f78b3bd11894c21e03455b7f1f7d

See more details on using hashes here.

File details

Details for the file pyckb-1.2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: pyckb-1.2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pyckb-1.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ded07ddde3760a23fb8cb23a95d070f82233479c7df0c30a275da972a90f0437
MD5 3662bbee2f58cf904e6d8963edd254ca
BLAKE2b-256 46f2e150692ab28f0ea713bb6a2cef2c9005057eafb66bd23ca2c28acae44ce0

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