Skip to main content

Introduction

This document describes how to develop python script to test and deploy contracts on Asimov using high level Python API.

Dependency

Install Python Environment

Before running python script, you need to install python and set up your virtual environment. Follow instructions on python.org and pyenv to finish the installation.
Asimov Python SDK has been fully tested on Python 3.7+.

Install secp256k1

It is an optimized C library for EC operations on curve secp256k1. Follow instructions on specp256k1 to finish the installation.

You need to install automake on MacOS to run the scripts in secp256k1. Run brew install automake.

Note: If you see the error message like Cannot import secp256k1: libsecp256k1.so.0: cannot open shared object file... when execute pip install py-asimov. You can add LIBDIR to the LD_LIBRARY_PATH environment variable like export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib on Fedora/CentOS/RHEL. (Let's assume LIBDIR is /usr/local/lib in this case).

Install gmp for fastecdsa

Py-Asimov use fastecdsa library for fast elliptic curve crypto. Note that you need to have a C compiler. You also need to have GMP on your system as the underlying C code in this package includes the gmp.h header (and links against gmp via the -lgmp flag). You can install all dependencies as follows:

apt

$ apt-get install python-dev libgmp3-dev

yum

$ yum install python-devel gmp-devel

mac

$ brew install gmp

Install Asimov Python SDK

pip install -i https://pypi.python.org/simple/ py-asimov

We provide high level Python API through Python SDK. Please visit Python API to read api specifications.

Install Asimov Smart Contract Compiler

Follow instructions on Asimov to finish the installation.

Tutorial

We provide a tutorial.py to cover the most used functions in Python SDK, including submit template, deploy contract, execute/vote on contract methods, read contract states and check transaction status and so on.

The smart contract test against in the above script is tutorial.sol.

Initialize Node Instance

from asimov import Node

node = Node() 

Setup RPC Server and Private Key

# set rpc server
node.set_rpc_server("http://seed.asimov.tech")

# set private key
node.set_private_key("your private key")

Submit Template

from asimov import Template
from asimov.constant import SUCCESS

# initialize template instance
t = Template(node)

# submit a contract template to Asimov blockchain
tx = t.submit("./contracts/tutorial.sol", "template_name", 'Tutorial')

# make sure the transaction is confirmed on chain before moving on to next step
assert tx.check() is SUCCESS

Deploy Contract

from asimov import Contract

# deploy a contract instance to Asimov blockchain
deploy_tx, contract_address = t.deploy_contract(tx.id)

# make sure the transaction is confirmed on chain before moving on to next step
assert tx.check() is SUCCESS

# initialize contract instance
contract = Contract(node, contract_address)

Execute Contract Methods

from asimov import constant

# mint asset
tx = contract.execute("mint", [10000 * constant.COIN])

# make sure the transaction is confirmed on chain and the contract execution is successful
assert tx.check() is constant.SUCCESS

# call contract's read only function.We get new asset type and convert to string type.
asset_type = Asset.asset2str(contract.read("assettype"))

# transfer asset
assert contract.execute("transfer", [node.address, 100 * constant.COIN]).check() is constant.SUCCESS

Vote Contract Methods

# call the vote method to vote using the utxo asset mint in the above step
assert contract.vote("vote", [88], 1, asset_type).check() is constant.SUCCESS

Developer Setup

If you would like to hack on py-asimov, please follow these steps:

  • Testing
  • Pull Requests
  • Code Style
  • Documentation

Development Environment Setup

You can set up your dev environment with:

git clone git@gitlab.asimov.work:asimov/asimov-python-sdk.git
cd pyasimov
pyenv virtualenv 3.7.3 env-asimov
pyenv activate env-asimov
pip install -e .[dev]

# If you're using zsh you need to escape square brackets: 
pip install -e .\[extra\]

Testing Setup

During development, you might like to have tests run on every file save.

# in the project root:
make test

Release setup

To release a new version:

make release bump=$$VERSION_PART_TO_BUMP$$

How to bumpversion

The version format for this repo is {major}.{minor}.{patch} for stable

To issue the next version in line, specify which part to bump, like make release bump=minor or make release bump=patch. This is typically done from the master branch. To include changes made with each release, update "docs/releases.rst" with the changes, and apply commit directly to master before release.

Metadata

Release files for py-asimov 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-asimov 0.3.0
File Size Uploaded Provenance Actions
py-asimov-0.3.0.tar.gz 22.3 kB Without provenance Details for py-asimov-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-asimov 0.3.0
File Interpreter ABI Platform Actions
py_asimov-0.3.0-py3-none-any.whl Python 3 none any Details for py_asimov-0.3.0-py3-none-any.whl

Total release size: 47.5 kB

Release files / py-asimov-0.3.0.tar.gz

Download URL py-asimov-0.3.0.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6ca1d0b49bcbdaac35ae10f727e01f8f35abfa3cfcbb35cfe5f78700f6f0a1c2
BLAKE2b-256 checksum
How to use checksums
9af62a48eab3bad529957b0d83bee57ca8e0826d27ec9705155d507f5804c778
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

Release files / py_asimov-0.3.0-py3-none-any.whl

Download URL py_asimov-0.3.0-py3-none-any.whl
Size 25.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9670be3b9d7f913be9b7e2de96e63064cda77677c58a311ff0602ed551f20d7
BLAKE2b-256 checksum
How to use checksums
9c46192a792788905f799740a3aa936ed8852901aa52f726679427bb7705af02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

Security for py-asimov 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page