Package: dsc-python-sdk
Decimal Python SDKCheck out these links:Decimal SDK docs.Decimal Console site.Wallet APIGenerate new walletfromdsc_sdkimportWalletwallet=Wallet()Generate wallet from mnemonic**if no mnemonic provided Wallet() will create instance with autogenerated mnemonicfromdsc_sdkimportWalletwallet=Wallet('erase august mask elevator sand picture north there apple equal anchor target...')Get wallet addressfromdsc_sdkimportWalletwallet=Wallet()wallet.get_address()# returns wallet addresswallet.get_mnemonic()# returns wallet mnemonicGet DecimalAPI to perform transactionsTo initiate api you have to pass address of the gateway for network you will work withfromdsc_sdkimportDscAPI# or you can use dsc_sdk.MAINNET_GATE, TESTNET_GATE, DEVNET_GATEapi=DscAPI("https://devnet-gate.decimalchain.com/api")# read chain id & base coin denominationapi.get_parameters()print(api.get_chain_id())print(api.get_base_denom())API usageAfter you initialized api instance, you can use its` broadcast() method to send prepared transaction.
Transaction creation examples can be found in this file.fromdsc_sdkimportDscAPIapi=DscAPI("https://devnet-gate.decimalchain.com/api")api.broadcast(prepared_transaction_bytes)Build and send transaction# all Msg* functions is defined in tx_types.pyfromdsc_sdkimportDscAPI,Wallet,Transaction,MsgSendCoin,...# helper functions to convert integer values to valid blockchain amountsfromdsc_sdkimportether_to_wei,finney_to_wei##### 1. initialize api# You can also use constants# MAINNET_GATE, TESTNET_GATE, DEVNET_GATE and MAINNET_WEB3, TESTNET_WEB3, DEVNET_WEB3api=DscAPI("https://devnet-gate.decimalchain.com/api","https://devnet-val.decimalchain.com/web3/")# or, if you don't want to use web3 from APIapi=DscAPI("https://devnet-gate.decimalchain.com/api")api.get_parameters()##### 2. create wallet and bind it to current blockchainwallet=Wallet(mnemonic1)an,seq=api.get_account_number_and_sequence(wallet.get_address())wallet.set_account_number(an)wallet.set_sequence(seq)wallet.set_chain_id(api.get_chain_id())##### 3. create and sign transaction# create transaction message# sender and recipient must be valid bech32 address# like d01...msg=MsgSendCoin(sender,recipient,coin_denom,ether_to_wei(1))tx=Transaction.build_tx(msg)# optional: set memo, set custom coin fee...tx.set_memo("hello from python")tx.set_fee("initiald",ether_to_wei(1))# calculate_fee calculates fee in specified denom and set it# wallet is used for signing and for right transaction lengthtx.calculate_fee(wallet,"initiald",api)# sign transaction and get transaction bytes to sendtx_bytes=tx.sign(wallet)##### 4. send transaction and examine resulttxres=api.broadcast(tx_bytes)print(txres.hash,txres.code,txres.codespace)Known transaction message types (constructors)NOTE:senderandrecipientmust be valid bech32 addresses withd0prefixvalidator...must be valid bech32 addresses withd0valoperprefixamountmust be integer value in string representationCoin module contructorsMsgCreateCoin(sender: str, denom: str, title: str, crr: int, initial_volume: str, initial_reserve: str, limit_volume: str,     identity: str)(Message to create custom coin)denom- short ticket for coin, first symbol must be letter, others must be letters and digits, up to 10 symbolscrr- constant reserve ratio, integer value between 10 and 100initial_volume,initial_reserve,limit_volume- big integers as string, inital amount of custom coin, initial reserve in base coin, limit for custom coin amountMsgUpdateCoin(sender: str, denom: str, limit_volume: str, identity: str)(Message to update custom coin limit volume and identity, only creator can update coin, limit must be greater than current volume)MsgBuyCoin(sender: str, denom_to_buy: str, amount_to_buy: str, denom_to_sell: str, max_amount_to_sell: str)(Message to buy coin)MsgSellCoin(sender: str, denom_to_sell: str, amount_to_sell: str, denom_to_buy: str, min_amount_to_buy: str)(Message to sell coin)MsgSendCoin(sender: str, recipient: str, denom: str, amount: str)(Message to send coin from sender to recipient)MsgMultiSendCoin(sender: str, sends: List[coin_tx.MultiSendEntry]), MultiSendEntry(recipient: str, denom: str, amount: str)(Message to send possible different coins for sender to multiple recipients)MsgBurnCoin(sender: str, denom: str, amount: str)(Message to burn coin volume (not reserve), coin will be substracted from sender balance)MsgRedeemCheck(sender: str, check: str, proof: str)(Message to redeem check)check- base58 encoded check bytesproof- password for checkhelper to send all coinsBuildSendAllCoin(signer: Wallet, api, recipient: str, coin_denom: str) -> bytes(return signed transaction bytes)BuildSellAllCoin(signer: Wallet, api, recipient: str, coin_sell: str, coin_buy: str) -> bytes(return signed transaction bytes)Multisig module contructorsMsgCreateWallet(sender: str, owners: List[str], weights: List[int], threshold: int)(Message to create multisig wallet)owners- list of valid account addressesweights- voting weights of ownersthreshold- threshold level to execute transactionMsgCreateTransaction(sender: str, wallet: str, msg)(Message to create multisig transaction, sender must be one of wallets owner)msg- result of any Msg* constructorMsgSignTransaction(sender: str, id: str)(Message to sign, sender must be one of wallets owner)id- multisig transaction id, bech32 value with prefixd0mstxNFT module constructorsMsgMintToken(sender: str, denom: str, token_id: str, token_uri: str, allow_mint: bool, recipient: str, quantity: int, reserve_denom: str, reserve_amount: str)(Message to mint NFT token)denom- name of NFT collectiontoken_id- blockchain unique token identifiertoken_uri- blockchain unique URIallow_mint- allow to mint subtokenrecipient- recipient of NFT subtokensquantity- amount of NFT subtokens to mintreserve_denom- denom of coin to reserve subtokensreserve_amount- amount of coin to reserve subtokens PER ONE SUBTOKENMsgUpdateToken(sender: str, token_id: str, token_uri: str)(Message to update token URI, only creator can do that)MsgUpdateReserve(sender: str, token_id: str, sub_token_ids: List[int], reserve_denom: str, reserve_amount: str)(Message to update subtokens reserve, only creator can do that)MsgSendToken(sender: str, recipient: str, token_id: str, sub_token_ids: List[int])(Message to send subtokens from sender to recipient)MsgBurnToken(sender: str, token_id: str, sub_token_ids: List[int])(Message to burn subtokens, only creator can do that, subtokens reserve will be return to creator)Swap module constructorsMsgInitializeSwap(sender: str, recipient: str, amount: str, token_symbol: str, transaction_number: str, from_chain: int, dest_chain: int)(Message to initialize coin swap from one blockchain to other)recipient- address in other blockchainamount- amount of coin/tokentoken_symbol- coin denom/token symboltransaction number- unique transaction numberfrom_chain- source blockchain id in swap chains recordsdest_chain- desctination blockchain id in swap chains recordsValidator module constructorsMsgCreateValidator(operator_address: str, reward_address: str, pubkey: bytes, moniker: str, identity: str, website: str, security_contact: str, details: str, commission: str, stake_denom: str, stake_amount: str)(Message to create validator)operator_address- sender address encoded as bech32 with prefixd0valoperreward_address- address to receive validator rewards, bech32 address with prefixd0pubkey- node public key bytesmoniker, indentity, website, security_contact, details- validator descriptioncommission- part of rewards to send toreward_address, must be string representation of floating point value between 0.0 and 1.0stake_denom, stake_amount- creator initial coin stakeMsgEditValidator(operator_address: str, reward_address: str, moniker: str, identity: str, website: str, security_contact: str, details: str)(Message to change validator reward address, description)MsgSetOnline(validator: str)(Message to set validator online)MsgSetOffline(validator: str)(Message to set validator offline)MsgDelegate(delegator: str, validator: str, coin_denom: str, coin_amount: str)(Message to delegate coin to validator)MsgDelegateNFT(delegator: str, validator: str, token_id: str, sub_token_ids: List[int])(Message to delegate NFT subtokens to validator)MsgRedelegate(delegator: str, validator_src: str, validator_dst: str, coin_denom: str, coin_amount: str)(Message to redelegate coins from one validator to other)MsgRedelegateNFT(delegator: str, validator_src: str, validator_dst: str, token_id: str, sub_token_ids: List[int])(Message to redelegate NFT subtokens from one validator to other)MsgUndelegate(delegator: str, validator: str, coin_denom: str, coin_amount: str)(Message to undelegate coin from validator)MsgUndelegateNFT(delegator: str, validator: str, token_id: str, sub_token_ids: List[int])(Message to undelegate NFT subtokens from validator)MsgCancelRedelegation(delegator: str, validator_src: str, validator_dst: str, creation_height: int, coin_denom: str, coin_amount: str)(Message to cancel coin redelegation)MsgCancelRedelegationNFT(delegator: str, validator_src: str, validator_dst: str, creation_height: int, token_id: str, sub_token_ids: List[int])(Message to cancel NFT subtoken redelegation)MsgCancelUndelegation(delegator: str, validator: str, creation_height: int, coin_denom: str, coin_amount: str)(Message to cancel coin undelegation)MsgCancelUndelegationNFT(delegator: str, validator: str, creation_height: int, token_id: str, sub_token_ids: List[int])(Message to cancel NFT subtokens undelegation)Known API query methodsget_account_balances(self, address: str) -> Dict[str, str]

get_account_erc_balances(self, hex_address: str) -> List[ERCBalance]

get_erc20_tokens(self, limit=10, offset=0)Helper functionsether_to_wei: convert integer value to valid amount representation ( * 10^18)finney_to_wei: convert integer value to valid amount representation ( * 10^15)wei_to_ether: convert amount string representation to float value ( / 10^18)check_address_validity: check bech32 address; return true if it's valid bech32 representationd0_to_hex,hex_to_d0: convert DSC address ith prefix d0 to/from Ethereum hex presentation