Skip to main content

Python SDK for Conflux network

Project description

Introduction

Binder Documentation Status gitlocalized codecov PyPI - Python Version

README | 中文文档

Overview

Python-conflux-sdk (or conflux-web3) helps to interact with Conflux network using python. It is built over web3.py and most of its APIs are consistent with web3.py.

Note: python-conflux-sdk v1.3.0 is the version compatible with web3.py v6.x. If you are using web3.py v7.x, please use the v1.4.0 or later.

Quickstart

Requirements: python version >= 3.8

$ pip3 install conflux-web3
from conflux_web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://test.confluxrpc.com"))

acct = w3.account.from_key("0xxxxxxxxxxxxxx")
w3.cfx.default_account = acct

# Uncomment the following line if there is not CFX in your account
# w3.cfx.contract(name="Faucet").claimCfx().transact().executed()

w3.cfx.send_transaction({
    'to': w3.address.zero_address(),
    'value': 10**18,
}).executed()

Or you can also use API as you do in web3.py before v6.20:

# modified from https://web3py.readthedocs.io/en/v6.20.2/transactions.html#chapter-1-w3-eth-send-transaction-signer-middleware
from conflux_web3 import Web3
w3 = Web3(Web3.HTTPProvider("https://test.confluxrpc.com"))
from conflux_web3.middleware import SignAndSendRawMiddlewareBuilder
from cfx_account import Account
acct = Account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530', network_id=w3.cfx.chain_id)
w3.middleware_onion.inject(SignAndSendRawMiddlewareBuilder.build(acct), layer=0)
w3.cfx.default_account = acct.address

transaction = {
    'to': w3.address.zero_address(),
    'value': 22,
}
w3.cfx.send_transaction(transaction)

Documentations

More detailed code examples are provided in the documentation.

Run Code Examples Online!

All code examples can be run online in mybinder. You can click 🚀 -> Binder on the top bar to activate the running environment. All dependencies wil be installed and the example can be run immediately.

Localization

Currently this documentation supports:

  • English version
  • Chinese version

And welcome to provide translation in GitLocalize.

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

conflux_web3-1.4.0b2.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

conflux_web3-1.4.0b2-py3-none-any.whl (77.7 kB view details)

Uploaded Python 3

File details

Details for the file conflux_web3-1.4.0b2.tar.gz.

File metadata

  • Download URL: conflux_web3-1.4.0b2.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for conflux_web3-1.4.0b2.tar.gz
Algorithm Hash digest
SHA256 daa3554a83f654a77b37764168b6abe557f46ec45d8da45e8b1fe2de1484bfa3
MD5 fd691439b5b384328e6ea48791cdb3a8
BLAKE2b-256 2664eb20979a67f9ce730f0a38f490a63ac24ad776aade101e03a8e7c979cef3

See more details on using hashes here.

File details

Details for the file conflux_web3-1.4.0b2-py3-none-any.whl.

File metadata

File hashes

Hashes for conflux_web3-1.4.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 3965e732d77b5e608785e33c4b0b14f607855a5284e774718861d2cc2fafa3ea
MD5 276f6ff31ba62a6d0bb55b34c44bfc28
BLAKE2b-256 3c79e645fb0dea6866d50620f29156c70a3b3167995f9128ea55acfbde62da5a

See more details on using hashes here.

Supported by

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