Package: py-asimov
IntroductionThis document describes how to develop python script to test and deploy contracts on Asimov using high level Python API.DependencyInstall Python EnvironmentBefore running python script, you need to install python and set up your virtual environment.
Follow instructions onpython.organdpyenvto finish the installation.Asimov Python SDK has been fully tested on Python 3.7+.Install secp256k1It is an optimized C library for EC operations on curve secp256k1.
Follow instructions onspecp256k1to finish the installation.You need to install automake on MacOS to run the scripts in secp256k1. Runbrew install automake.Note: If you see the error message likeCannot import secp256k1: libsecp256k1.so.0: cannot open shared object file...when executepip install py-asimov. You can addLIBDIRto theLD_LIBRARY_PATHenvironment variable likeexport LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/libon Fedora/CentOS/RHEL. (Let's assumeLIBDIRis/usr/local/libin this case).Install gmp for fastecdsaPy-Asimov usefastecdsalibrary for fast elliptic curve crypto.
Note that you need to have a C compiler. You also need to haveGMPon your system as the underlying C code in this package includes thegmp.hheader (and links against gmp via the-lgmpflag). You can install all dependencies as follows:apt$apt-getinstallpython-devlibgmp3-devyum$yuminstallpython-develgmp-develmac$brewinstallgmpInstall Asimov Python SDKpipinstall-ihttps://pypi.python.org/simple/py-asimovWe provide high level Python API through Python SDK. Please visitPython APIto read api specifications.Install Asimov Smart Contract CompilerFollow instructions onAsimovto finish the installation.TutorialWe provide atutorial.pyto cover the most used functions in Python SDK,
includingsubmit template,deploy contract,execute/vote on contract methods,read contract statesandcheck transaction statusand so on.The smart contract test against in the above script istutorial.sol.Initialize Node InstancefromasimovimportNodenode=Node()Setup RPC Server and Private Key# set rpc servernode.set_rpc_server("http://seed.asimov.tech")# set private keynode.set_private_key("your private key")Submit TemplatefromasimovimportTemplatefromasimov.constantimportSUCCESS# initialize template instancet=Template(node)# submit a contract template to Asimov blockchaintx=t.submit("./contracts/tutorial.sol","template_name",'Tutorial')# make sure the transaction is confirmed on chain before moving on to next stepasserttx.check()isSUCCESSDeploy ContractfromasimovimportContract# deploy a contract instance to Asimov blockchaindeploy_tx,contract_address=t.deploy_contract(tx.id)# make sure the transaction is confirmed on chain before moving on to next stepasserttx.check()isSUCCESS# initialize contract instancecontract=Contract(node,contract_address)Execute Contract Methodsfromasimovimportconstant# mint assettx=contract.execute("mint",[10000*constant.COIN])# make sure the transaction is confirmed on chain and the contract execution is successfulasserttx.check()isconstant.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 assetassertcontract.execute("transfer",[node.address,100*constant.COIN]).check()isconstant.SUCCESSVote Contract Methods# call the vote method to vote using the utxo asset mint in the above stepassertcontract.vote("vote",[88],1,asset_type).check()isconstant.SUCCESSDeveloper SetupIf you would like to hack on py-asimov, please follow these steps:TestingPull RequestsCode StyleDocumentationDevelopment Environment SetupYou can set up your dev environment with:gitclonegit@gitlab.asimov.work:asimov/asimov-python-sdk.gitcdpyasimov
pyenvvirtualenv3.7.3env-asimov
pyenvactivateenv-asimov
pipinstall-e.[dev]# If you're using zsh you need to escape square brackets:pipinstall-e.\[extra\]Testing SetupDuring development, you might like to have tests run on every file save.# in the project root:maketestRelease setupTo release a new version:makereleasebump=$$VERSION_PART_TO_BUMP$$How to bumpversionThe version format for this repo is{major}.{minor}.{patch}for stableTo issue the next version in line, specify which part to bump,
likemake release bump=minorormake 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.