Skip to main content

A tool for access to SKALE smart contracts

Project description

SKALE Contracts Python

Description

The library simplifies development of dApps that interact with smart contracts in SKALE infrastructure using python.

Features

  • Resolving of addresses of SKALE contracts on different networks
  • Providing up to date ABI for SKALE contracts (they may change over time due to upgradeable nature of some contracts)
  • Automatic creation of Contract objects using web3
  • Supports web3 library versions >= 7, < 8

Importing the library

pip install skale-contracts

Setup repo locally

  1. Clone the repo
git clone --recurse-submodules https://github.com/skalenetwork/skale-contracts.git && cd skale-contracts
  1. Install dependencies
cd python && pip install -e . && pip3 install -r scripts/requirements.txt && pip3 install -r tests/requirements.txt

Running tests (python)

  1. set ENDPOINT environment variable using either option:

    export ENDPOINT="http://my.mainnet.endpoint/my-api-key"
    

    or

    echo 'ENDPOINT="http://my.mainnet.endpoint/my-api-key"' > .env
    
  2. run tests

pytest -v
  1. run tests with coverage report (optional)
pytest --cov=./ --cov-report=xml -v

The tests require reliable network connection as they will fetch information like: - stable versions of skale projects - deployed versions of skale projects - ABIs of smart-contracts - perform read operations to some deployed smart-contracts on Mainnet and SKALE's Europa-chain

Glossary

Main abstractions used by the library are provided below:

Network

Represents the blockchain where smart contracts are deployed.

It could be Ethereum mainnet, goerli, SKALE chain or similar ethereum compatible chain.

Project

SKALE set of smart contracts grouped into a project to serve a particular purpose.

Examples of projects are IMA, skale-manager or etherbase.

Instance

An instance represents a particular project deployed to a particular network.

For example IMA on Ethereum mainnet or etherbase on some of SKALE chains.

Alias

An alias is a textual name of an instance.

Usage

The library provides a master object skale_contracts.

This object is used to provide the desired network, project and instance using it's alias or direct address.

By instantiating a particular instance, it can be queried for information (address, ABI or Contract object) about a particular contract by it's name.

Usage Example

from web3 import HTTPProvider, Web3
from skale_contracts import skale_contracts
from skale_contracts.project_factory import SkaleProject, create_project
from skale_contracts.projects.skale_manager import SkaleManagerContract

# Any provider type that inherits from web3 BaseProvider
provider = Web3.HTTPProvider(MAINNET_ENDPOINT)
network = skale_contracts.get_network_by_provider(provider)
project = create_project(network, SkaleProject.SKALE_MANAGER)

# loading production instance of skale-manager deployed on ethereum mainnet
instance = project.get_instance('production')

# returns all contract names that can be queried using this instance
all_contract_names = instance.get_contract_names()

# get specific contract object
skale_manager_contract = instance.getContract(SkaleManagerContract.SKALE_MANAGER)

# will query the smart-contract. In this case, queries the version set in SkaleManager.sol
version = skale_manager_contract.functions.version().call()

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

skale_contracts-2.0.0.dev5168047825711286878.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file skale_contracts-2.0.0.dev5168047825711286878.tar.gz.

File metadata

File hashes

Hashes for skale_contracts-2.0.0.dev5168047825711286878.tar.gz
Algorithm Hash digest
SHA256 ca498c907e522f1cfe6ffee57358f050956bf1fb26e8590c7e3545935908d101
MD5 9617a664783b1fc40e140e23fa92186d
BLAKE2b-256 cd437a48a54ea271eedfd95751befa55581dd0e3c261930e4e5ac9a663714ec6

See more details on using hashes here.

File details

Details for the file skale_contracts-2.0.0.dev5168047825711286878-py3-none-any.whl.

File metadata

File hashes

Hashes for skale_contracts-2.0.0.dev5168047825711286878-py3-none-any.whl
Algorithm Hash digest
SHA256 60ffe5dfde9e5edb17e34373a7a0ace55d5e3c4a71ef9d8e356028264ae8cb0b
MD5 d9735a291e3c76aae6daa09bc4277f67
BLAKE2b-256 7499213d16257db2ec2a18b00fc6e53dc3c35c941edaa7308aa0dd9e31c6ea24

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