Package: minter-sdk
Python SDKPorted from official Minter'sphp SDKCreated byhttps://www.u-node.net's masternode co-founder Roman MatusevichYou can support our project by sending any Minter's coins to our wallet Mx6e0cd64694b1e143adaa7d4914080e748837aec9Feel free to delegate to our 3% masternode Mp02bc3c3f77d5ab9732ef9fc3801a6d72dc18f88328c14dc735648abfe551f50fInstallationpip install minter-sdkUsing APIfrommintersdk.minterapiimportMinterAPInode_url='https://minter-node-1.testnet.minter.network:8841'# Example of a node urlapi=MinterAPI(api_url=node_url)# 'connect_timeout', 'read_timeout', 'headers' kwargs would be passed to request, if providedapi=MinterAPI(api_url=node_url,connect_timeout=1,read_timeout=3,headers={})Numeric strings automatically are converted to integers inresponse['result']dict.Some API methods acceptpip2bip (bool)argument to convert coin values from PIP to BIP.Values areDecimaltype after conversion.Methodsget_addresses(addresses, height=None, pip2bip=False)Returns addresses balances.get_balance(address, height=None, pip2bip=False)Returns coins list, balance and transaction count (for nonce) of an address.get_block(height, pip2bip=False)Returns block data at given height.get_candidate(public_key, height=None, pip2bip=False)Returns candidate’s info by provided public_key. It will respond with 404 code if candidate is not found.get_candidates(height=None, include_stakes=False, pip2bip=False)Returns list of candidates.get_coin_info(symbol, height=None, pip2bip=False)Returns information about coin. Note: this method does not return information about base coins (MNT and BIP).get_events(height, pip2bip=False)Returns events at given height.get_genesis(pip2bip=False)Return network genesis.get_latest_block_height()Returns latest block height.get_max_gas_price(height=None)Returns current max gas price.get_min_gas_price()Returns current min gas price.get_missed_blocks(public_key, height=None)Returns missed blocks by validator public key.get_network_info()Return node network information.get_nonce(address)Returns next transaction number (nonce) of an address.get_status()Returns node status info.get_transaction(tx_hash, pip2bip=False, decode_payload=False)Returns transaction info.get_transactions(query, page=None, limit=None, pip2bip=False, decode_payload=False)Return transactions by query.get_unconfirmed_transactions(limit=None)Returns unconfirmed transactions.get_validators(height=None, page=None, limit=None)Returns list of active validators.estimate_coin_buy(coin_to_sell, value_to_buy, coin_to_buy, height=None, pip2bip=False)Return estimate of buy coin transaction.Provide value in PIP ifpip2bip is Falseor in BIP ifpip2bip is Trueestimate_coin_sell(coin_to_sell, value_to_sell, coin_to_buy, height=None, pip2bip=False)Return estimate of sell coin transaction.Provide value in PIP ifpip2bip is Falseor in BIP ifpip2bip is Trueestimate_coin_sell_all(coin_to_sell, value_to_sell, coin_to_buy, height=None, pip2bip=False)Return estimate of sell all coin transaction.Provide value in PIP ifpip2bip is Falseor in BIP ifpip2bip is Trueestimate_tx_commission(tx, height=None, pip2bip=False)Return estimate of transaction.send_transaction(tx)Returns the result of sending signed tx.SDK useCreate transactionsEach Minter transaction requiresnonce, gas_cointo be passed.  Also you can passpayload, chain_id, gas_price.MiterTx(nonce, gas_coin, payload='', service_data='', chain_id=1, gas_price=1, **kwargs)To create Minter transaction you MUST use concrete transaction class.All transaction values should be passed in BIP, you shouldn't convert them to PIP.All coin symbols are case insensitive, e.g. you can passgas_coin='BIP'orgas_coin='bip'TransactionsMinterBuyCoinTxfrommintersdk.sdk.transactionsimportMinterBuyCoinTxtx=MinterBuyCoinTx(coin_to_buy='SYMBOL',value_to_buy=1,coin_to_sell='SYMBOL',max_value_to_sell=2,nonce=1,gas_coin='SYMBOL')MinterCreateCoinTxfrommintersdk.sdk.transactionsimportMinterCreateCoinTxtx=MinterCreateCoinTx(name='Coin description',symbol='SYMBOL',initial_amount=1.5,initial_reserve=10000,crr=50,max_supply=1000,nonce=1,gas_coin='SYMBOL')MinterDeclareCandidacyTxfrommintersdk.sdk.transactionsimportMinterDeclareCandidacyTxtx=MinterDeclareCandidacyTx(address='Mx...',pub_key='Mp...',commission=1,coin='SYMBOL',stake=100,nonce=1,gas_coin='SYMBOL')MinterDelegateTxfrommintersdk.sdk.transactionsimportMinterDelegateTxtx=MinterDelegateTx(pub_key='Mp...',coin='SYMBOL',stake=100,nonce=1,gas_coin='SYMBOL')MinterRedeemCheckTxfrommintersdk.sdk.transactionsimportMinterRedeemCheckTxtx=MinterRedeemCheckTx(check='check hash str',proof='proof hash str',nonce=1,gas_coin='SYMBOL')MinterSellAllCoinTxfrommintersdk.sdk.transactionsimportMinterSellAllCoinTxtx=MinterSellAllCoinTx(coin_to_sell='SYMBOL',coin_to_buy='SYMBOL',min_value_to_buy=100,nonce=1,gas_coin='SYMBOL')MinterSellCoinTxfrommintersdk.sdk.transactionsimportMinterSellCoinTxtx=MinterSellCoinTx(coin_to_sell='SYMBOL',value_to_sell=1,coin_to_buy='SYMBOL',min_value_to_buy=2,nonce=1,gas_coin='SYMBOL')MinterSendCoinTxfrommintersdk.sdk.transactionsimportMinterSendCoinTxtx=MinterSendCoinTx(coin='SYMBOL',to='Mx...',value=5,nonce=1,gas_coin='SYMBOL')MinterMultiSendCoinTxfrommintersdk.sdk.transactionsimportMinterMultiSendCoinTxtxs=[{'coin':'SYMBOL','to':'Mx..1','value':5},{'coin':'SYMBOL','to':'Mx..2','value':1},{'coin':'SYMBOL','to':'Mx..3','value':4}]tx=MinterMultiSendCoinTx(txs=txs,nonce=1,gas_coin='SYMBOL')MinterSetCandidateOffTxfrommintersdk.sdk.transactionsimportMinterSetCandidateOffTxtx=MinterSetCandidateOffTx(pub_key='Mp...',nonce=1,gas_coin='SYMBOL')MinterSetCandidateOnTxfrommintersdk.sdk.transactionsimportMinterSetCandidateOnTxtx=MinterSetCandidateOnTx(pub_key='Mp...',nonce=1,gas_coin='SYMBOL')MinterUnbondTxfrommintersdk.sdk.transactionsimportMinterUnbondTxtx=MinterUnbondTx(pub_key='Mp...',coin='SYMBOL',value=100,nonce=1,gas_coin='SYMBOL')MinterEditCandidateTxfrommintersdk.sdk.transactionsimportMinterEditCandidateTxtx=MinterEditCandidateTx(pub_key='Mp...',reward_address='Mx...',owner_address='Mx...',nonce=1,gas_coin='SYMBOL')MinterCreateMultisigTxfrommintersdk.sdk.transactionsimportMinterCreateMultisigTxtx=MinterCreateMultisigTx(threshold=5,weights=[1,2,3],addresses=['Mx...','Mx...','Mx...'],nonce=1,gas_coin='SYMBOL')Sign transactionWhen your transaction object is created, you can sign it.
Every transaction can be signed by private key or/and by signature.Keep in mind, we have sometx = MinterSomeTx(...)and APIapi = MinterAPI(...)Sign single signature type transaction# Sign with private keytx.sign(private_key='PRIVATE_KEY')# Sign with signaturetx.signature_type=tx.SIGNATURE_SINGLE_TYPEsignature=tx.generate_signature(private_key='PRIVATE_KEY')tx.sign(signature=signature)Sign multi signature type transaction# Sign with private keystx.sign(private_key=['PRIVATE_KEY_1','PRIVATE_KEY_2',...],ms_address='Multisig address Mx...')# Sign with signaturestx.signature_type=tx.SIGNATURE_MULTI_TYPEsignature_1=tx.generate_signature(private_key='PRIVATE_KEY_1')signature_2=tx.generate_signature(private_key='PRIVATE_KEY_2')tx.sign(signature=[signature_1,signature_2],ms_address='Multisig address Mx...')# Sign with both private keys and signaturestx.signature_type=tx.SIGNATURE_MULTI_TYPEprivate_key_1='PRIVATE_KEY_1'private_key_2='PRIVATE_KEY_2'signature_1=tx.generate_signature(private_key='PRIVATE_KEY_3')signature_2=tx.generate_signature(private_key='PRIVATE_KEY_4')tx.sign(private_key=[private_key_1,private_key_2],signature=[signature_1,signature_2],ms_address='Multisig address Mx...'))As you see above, to generate signature we must set transactionsignature_typebefore generating signature.You can set this argument while creating transaction.tx = MinterSomeTx(..., signature_type=MinterTx.SIGNATURE_MULTI_TYPE)tx = MinterSomeTx(..., signature_type=MinterTx.SIGNATURE_SINGLE_TYPE)After that you can simply generate signature without setting it's signature type by overriding attribute.signature = tx.generate_signature(private_key='PRIVATE_KEY')Adding signature to multi signature type transactionWhen multi signature transaction is created it can be partially signed, e.g. signed by 2 of 3 private keys.Then partially signed transaction can be transferred to another client and this client can add own signature to transaction.frommintersdk.sdk.transactionsimportMinterTx# Client 1# Create transactiontx=MinterSomeTx(...)# Sign transactiontx.sign(private_key=['PK_1','PK_2'],ms_address='Mx...')# Then tx.signed_tx is transferred to Client 2# Client 2# Received raw_tx (tx.signed_tx from Client 1)tx=MinterTx.add_signature(signed_tx=raw_tx,private_key='PK_3')Client 2 will get new tx object with client's 2 signature.Client 2 may passtx.signed_txto next client or just sendtx.signed_txto the network.Send transactionWhen transaction is created and signed, you can send transaction to network. Signed transaction for sending can be found intx.signed_txattribute.# Create transactiontx=MinterSomeTx(...)# Sign transactiontx.sign(...)# Send transactionresponse=api.send_transaction(tx=tx.signed_tx)Create transaction from rawYou can create transaction object from raw transaction hash. You will get tx object of tx type.frommintersdk.sdk.transactionsimportMinterTxtx=MinterTx.from_raw(raw_tx='...')Minter deeplinkLet's create a MinterSendCoinTxfrommintersdk.sdk.transactionsimportMinterSendCoinTxtx=MinterSendCoinTx(coin='BIP',to='Mx18467bbb64a8edf890201d526c35957d82be3d95',value=1.23456789,nonce=1,gas_coin='MNT',gas_price=1,payload='Hello World')Now it's time to create deeplinkfrommintersdk.sdk.deeplinkimportMinterDeeplinkdl=MinterDeeplink(tx=tx,data_only=False)# Deeplink is generated by all tx params (nonce, gas_price, gas_coin, payload) by default.# If you want to create deeplink only by tx data, set `data_only=True`After deeplink object is created, you can override it's attributes, e.g.dl=MinterDeeplink(tx=tx)dl.nonce=''dl.gas_coin='MNT'dl.gas_price=10When your deeplink object is ready, generate iturl_link=dl.generate()# If password check is needed, pass password to generate methodurl_link=dl.generate(password='mystrongpassword')Then you might want to create QR-code from your deeplinkfrommintersdkimportMinterHelperqr_code_filepath=MinterHelper.generate_qr(text=url_link)# For additional params information for `MinterHelper.generate_qr()`, please see sourcecode for this method.Minter checkCreate and sign checkfrommintersdk.sdk.checkimportMinterCheck# Create check without passwordcheck=MinterCheck(nonce=1,due_block=300000,coin='MNT',value=1,gas_coin='MNT')# Or create check with passwordcheck=MinterCheck(nonce=1,due_block=300000,coin='MNT',value=1,gas_coin='MNT',passphrase='pass')# Sign checksigned_check=check.sign(private_key='PRIVATE_KEY')Create prooffrommintersdk.sdk.checkimportMinterCheckproof=MinterCheck.proof(address='Mx...',passphrase='pass')Create check object from rawfrommintersdk.sdk.checkimportMinterCheck# Create and sign checkcheck=MinterCheck(nonce=1,due_block=300000,coin='MNT',value=1,gas_coin='MNT')signed_check=check.sign(private_key='PRIVATE_KEY')# Create object from signed checkcheck=MinterCheck.from_raw(rawcheck=signed_check)Minter Walletfrommintersdk.sdk.walletimportMinterWallet# Create new walletwallet=MinterWallet.create()# Get wallet data from existing mnemonicwallet=MinterWallet.create(mnemonic='YOUR MNEMONIC PHRASE')HelpersConvert between PIP and BIPfrommintersdk.shortcutsimportto_pip,to_bip# Get BIP from PIPpip_value=1000000000000000000bip_value=to_bip(pip_value)# Get PIP from BIPbip_value=100pip_value=to_pip(bip_value)