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://test.pypi.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.

Download files

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

Source Distribution

py-asimov-0.1.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

py_asimov-0.1.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file py-asimov-0.1.0.tar.gz.

File metadata

  • Download URL: py-asimov-0.1.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for py-asimov-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0903415bcb24a41347863ee5b238504f96399454af47377fda3b4124382e355e
MD5 89945de6867b051ca8d6c7f0cbea9811
BLAKE2b-256 71b9fe9667a0cba1c91b9a2fc6b678d68309cf526b481507a7867df9c3774281

See more details on using hashes here.

File details

Details for the file py_asimov-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_asimov-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for py_asimov-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07803a7a3bf13112de6f97de58a982046aab2e253c9a39585827969a1d4c744a
MD5 15bdc799a6ed79c91fd697a3357677b9
BLAKE2b-256 533d7a8695dc5fff1223e947698f957c7cf3d4330b3969d5709b754d57806283

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.1.0 This release

2 files

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