Here is a repository of simple Python scripts to send Conflux transactions on both Core Space and eSpace.
I had been using them myself to automate common tasks I wanted to perform on Conflux and decided to share with the community so everyone has the ability to use and learn from them.
Each is self-contained, has all inputs available inline (in the code) and can be run with minimal technical knowledge, explanation has been added in the way of comments to explain the concepts involved.
See Private Key management section below for best practices
Hopefully they are a resource to learn from if you are not already familiar with the requirements of sending transactions programmatically.
The four scripts available currently are:
core_send.py
- Send CFX on Conflux Core Space
core_transfer_evm.py
- Cross-Space CFX from Conflux Core Space to Conflux eSpace
- Utilizes the Conflux internal contract: CrossSpaceCall
espace_send.py
- Send CFX on Conflux eSpace
- Include a message
espace_swap.py
- Swap CFX for an ERC-20 token using https://swappi.io
Download or clone from here
requirements
- web3.py
-
conflux-web3
– Only a hard requirement for Core Space transactions
install requirements
pip install -r requirements.txt
Shared features
Batching
All scripts with the exception of espace_swap.py
have the ability to send multiple transactions. They are first built and signed in batch and then sent in batch.
A boolen flag repeat_one
further determines if you want to send the same transaction inputs multiple times or would like to provide unique inputs for each transaction.
For simplicity and accessibility especially for beginner users, the features are inline in each script and explicitly commented.
WEI explanation
- For example value = 1 means 1wei or 0.000000000000000001 CFX)
- Use web3.to_wei for conversion:
- web3.to_wei(1, “gwei”) == 1000000000 == 0.000000001 CFX
- web3.to_wei(1, “ether”) == 1000000000000000000 == 1 CFX
- Use web3.to_wei for conversion:
Report
Report printed to the console showing:
- Number of transactions sent
- Total time taken to send transactions
- From address
- Contract Utilized address (if applicable)
- To[Last]: the
to
address parameter of the last transaction - Gas Used
- Last Nonce hash for tracing on Confluxscan
- Last Nonce #
- Last transaction receipt data
Private Key Management
- All scripts require a wallet private key to sign transactions.
- The best practice is to set private keys as environment variables via terminal or add a .env script. This is HIGHLY recommended and all scripts are setup to read private keys from ENV variables
As a fallback, they can be pasted into
yourprivatekey
variable within the script
But be CARFEFUL, NEVER EVER share your private key.
Below are examples of how to set the environment variables
Windows Command Shell
set private_key_core=abc123
set private_key_evm=def456
Jupyter Notebook
! set private_key_core=abc123
! set private_key_evm=def456
MacOS and *nix shell
export private_key_core=abc123
export private_key_evm=def456