Skip to main content

SDK for deploying and interacting with smart contracts on Polkadot/Kusama networks

Project description

Polkadot Smart Contract SDK

A simple SDK for deploying and interacting with smart contracts on Polkadot/Kusama networks. Write Python code and deploy it directly to the blockchain!

Installation

pip install polkadot-contract-sdk

Quick Start

1. Deploy a Contract

Create a Python file main.py:

def multiply_numbers(a, b):
    return a * b

def main():
    print(multiply_numbers(2, 3))

if __name__ == "__main__":
    main()

Deploy it:

sdk-deploy-contract main.py

2. Interact with a Contract

# Use contract address from deployment.json
sdk-interact

# Or specify contract address directly
sdk-interact 0x1234567890123456789012345678901234567890

Setup

Set your private key as an environment variable:

export PRIVATE_KEY='your_private_key_here'

Or create a .env file:

PRIVATE_KEY=your_private_key_here

Commands

sdk-deploy-contract

Deploy a Python file as a smart contract.

sdk-deploy-contract <python-file> [options]

Options:

  • -o, --output: Output file for deployment information (default: deployment.json)
  • -r, --rpc: Custom RPC URL (default: Moonbase Alpha testnet)

Example:

sdk-deploy-contract main.py -o my_deployment.json

sdk-interact

Interact with a deployed smart contract.

sdk-interact [contract-address] [options]

Options:

  • -p, --python-file: Path to original Python file (default: main.py)
  • -d, --deployment: Path to deployment.json (default: deployment.json)
  • -r, --rpc: Custom RPC URL (default: Moonbase Alpha testnet)

Examples:

# Load from deployment.json
sdk-interact

# Use specific contract address
sdk-interact 0x1234567890123456789012345678901234567890

# Custom files
sdk-interact -p my_contract.py -d my_deployment.json

How It Works

  1. Deployment: The SDK reads your Python file, extracts functions, and compiles them to blockchain bytecode. Internally, it uses Solidity as an intermediate step, but you only write Python code.

  2. Interaction: The SDK reads your original Python file to discover available functions and provides an interactive menu to call them on the deployed contract.

Requirements

  • Python 3.8+
  • web3>=6.0.0
  • py-solc-x>=1.1.1
  • python-dotenv>=1.0.0

Network Support

  • Moonbase Alpha (Testnet) - Default
  • Moonriver (Kusama Parachain)
  • Any EVM-compatible network via custom RPC URL

Getting Testnet Tokens

For Moonbase Alpha testnet, get free tokens from: https://faucet.moonbeam.network/

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

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

polkadot_contract_sdk-1.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

polkadot_contract_sdk-1.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file polkadot_contract_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: polkadot_contract_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for polkadot_contract_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e885be8e050e825d6501197972ae22e8f1ae049f0f869c2af2d4cfb778f4f778
MD5 934184a4eb8625a1b2b2c1d14529d657
BLAKE2b-256 8886bb671eac71d208e6466fa92f5e6191f811a1865d7e06a904e62a27db1dc6

See more details on using hashes here.

File details

Details for the file polkadot_contract_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polkadot_contract_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9961a474e2f60e05b1d91ab2db4793becc5d68cb89782858b7e81557b5199d78
MD5 c95a31f8bd80ded04229ca41294468a7
BLAKE2b-256 def885901435b326ca462a9e52669b07b267b2ff8cece8b485a26333e1947ab0

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