Package: nanohakase
NanohakaseNanohakase is a python library for the Nano cryptocurrency. It aims to be the simplest Nano library out there, and is a self fork of Bananopie (Nanopie was taken already).Installationpip install nanohakaseNanohakase is onpypi.Quick StartFirst, start with aRPCclass, for read onlyfromnanohakaseimport*rpc=RPC("https://proxy.nanos.cc/proxy")#check current blockcountprint(rpc.get_block_count().count)#get last 10 transactionsprint(rpc.get_account_history("nano_3346kkobb11qqpo17imgiybmwrgibr7yi34mwn5j6uywyke8f7fnfp94uyps",count=10)["history"])#check balanceprint(raw_to_whole(int(rpc.get_account_balance("nano_3346kkobb11qqpo17imgiybmwrgibr7yi34mwn5j6uywyke8f7fnfp94uyps")["balance"])))For sending/receiving transactions, use aWallet.fromnanohakaseimportRPC,Walletrpc=RPC("https://app.natrium.io/api")my_account=Wallet(rpc,seed="seed here",index=0)#or generate a new onemy_new_account=Wallet(rpc,index=0)print(my_new_account.seed)#get address of selfprint(my_account.get_address())#get balance of selfprint(my_account.get_balance())#send 1 nano to the faucet development fundprint(my_account.send("nano_3pdripjhteyymwjnaspc5nd96gyxgcdxcskiwwwoqxttnrncrxi974riid94","1"))#receive fundsmy_account.receive_all()#change repmy_account.change_rep("nano_1kd4h9nqaxengni43xy9775gcag8ptw8ddjifnm77qes1efuoqikoqy5sjq3")#change seed indexmy_account.index=2Utility functions are also provided.importnanohakase#whole to raw nanoprint(nanohakase.whole_to_raw("492.2"))#raw to whole nanoprint(nanohakase.raw_to_whole(1900000000000000000000000000))DocumentationAlso see theNano RPC docsfor information on what rpc call wrapper functions return.RPC (Class)Parameters:rpc_url(str): IP or URL of nodeauth(strorbool, Default: False): Optional HTTP Authorization headerSample:rpc=RPC("https://proxy.nanos.cc/proxy")Properties:rpc_url(str): IP or URL of nodeauth(strorbool): Optional HTTP Authorization headerMethods:call (Function)RPC call. Intended for internal use, but useful for RPC calls that aren't directly implemented.Parameters:payload(dictionary): Payload to send to nodeSample:rpc.call({"action":"block_count"})Returns:Response of RPC call (JSON dictionary)get_block_count (Function)Get network block count.ParametersNoneReturns:SeeNano RPC Docsget_block_info (Function)Get block info for hash.Parametersblock(st): Block hashReturns:SeeNano RPC Docsget_blocks (Function)Get blocks.Parametersblocks(str list): List of block hashes to get information onReturns:SeeNano RPC Docsget_blocks_info (Function)Get blocks, with more detailed information.Parametersblocks(str list): List of block hashes to get information onReturns:SeeNano RPC Docsget_representatives (Function)Get list of network representatives and their weightParametersNoneReturns:SeeNano RPC Docsget_representatives_online (Function)Get list of network representatives that have recently votedParametersNoneReturns:SeeNano RPC Docsget_account_history (Function)Get account history (confirmed and received transaction list)Parametersaccount(str): Address of accountcount(int, Default: -1): Optional parameter to specify amount of transactions to return.-1means all, or at least as much as the node will allowReturns:SeeNano RPC Docsget_account_info (Function)Get account information, like height, frontier, balance, etcParametersaccount(str): Address of accountReturns:SeeNano RPC Docsget_account_balance (Function)Get account balanceParametersaccount(str): Address of accountReturns:SeeNano RPC Docsget_account_representative (Function)Get account representativeParametersaccount(str): Address of accountReturns:SeeNano RPC Docsget_accounts_representatives (Function)Get representatives of accountsParametersaccount(str list): List of addressesReturns:SeeNano RPC Docsget_account_weight (Function)Get delegated weight of representativeParametersaccount(str): Address of representativeReturns:SeeNano RPC Docsget_receivable (Function)Get receivable transactions for accountParametersaccount(str): Address of representativecount(int, Default: 20): Optional parameter to specify max amount of receivable transactions to returnthereshold(int or bool, Default: False): Optional parameter to filter out any receivable transactions with value less than the theresholdReturns:SeeNano RPC DocsWallet (class)Parameters:rpc(RPC): A RPC classseed(strorbool, Default: False): 64 character hex seed, ifFalse, will generate a seed by itself. Private keys are derived from the seed.index(int, Default: 0): Optional parameter that is the index of the seed. Any number from 0 to 4294967295. Each index of the seed is a different private key, and so different address.Sample:my_wallet=Wallet(RPC("https://proxy.nanos.cc/proxy"),"seed here",0)Properties:rpc_url(str): IP or URL of nodeseed(str): Nano seed (64 character hex string)index(int): Seed index. Change this property to change the wallet seed index.Methodssend_process (Function)Internal use function to send aprocessRPC callParametersblock(dictionary): block contentsubtype(str): Send, receive, or changeReturnsSeeNano RPC Docssend (Function)High level function to send NanoParametersto(str): Address to send toamount(str): Amount of Nano to send (in whole, not raw)work(strorbool, Default: False): Leave it as False to ask node to generate work (passesdo_work). Put in a work string if work generated locallySample:my_wallet=Wallet(RPC("https://app.natrium.io/api"),"seed here",0)my_account.send("nano_3pdripjhteyymwjnaspc5nd96gyxgcdxcskiwwwoqxttnrncrxi974riid94","1")ReturnsSeeNano RPC Docsreceive_specific (Function)Receive a specific blockParametershash(str): Block hash to receivework(strorbool, Default: False): Leave it as False to ask node to generate work (passesdo_work). Put in a work string if work generated locallyReturnsSeeNano RPC Docsreceive_all (Function)Receive all (technically, 20) receivable transactionsParametersNoneSample:my_wallet=Wallet(RPC("https://proxy.nanos.cc/proxy"),"seed here",0)my_account.receive_all()ReturnsNothingchange_rep (Function)Change account representativeParametersnew_representative(str): Representative Nano address to change towork(strorbool, Default: False): Leave it as False to ask node to generate work (passesdo_work). Put in a work string if work generated locallySample:my_wallet=Wallet(RPC("https://proxy.nanos.cc/proxy"),"seed here",0)my_account.change_rep("nano_1kd4h9nqaxengni43xy9775gcag8ptw8ddjifnm77qes1efuoqikoqy5sjq3")ReturnsSeeNano RPC Docsget_address (Function)Get address at current index of current seedParametersNoneReturnsstr, Nano addressget_balance (Function)Double wrapped function to get balance of self (seeRPC'sget_account_balance)get_receivable (Function)Double wrapped function to get receivable blocks (seeRPC'sget_receivable)get_representative (Function)Double wrapped function to get representative of self (seeRPC'sget_account_representative)get_account_info (Function)Double wrapped function to get account info of self (seeRPC'sget_account_info)generate_seed (static Function)Generate a random seed usingos.urandomParametersNoneSample:print(Wallet.generate_seed())Returns64 character hex seedUtilPropertiesNANO_DECIMALS(int): Amount of decimals that Nano has (30)PREAMBLE(str): Hex string to prepend when signingMethodsencode_base32,decode_base32,bytes_to_hex,hex_to_bytes,random_bytes,get_private_key_from_seed,get_public_key_from_private_key,get_address_from_public_key,get_public_key_from_address,hash_block,signare internal use Functions that are currently undocumented. Look at/nanohakase/util.pyto see what they do.whole_to_raw (Function)Converts whole Nano to raw NanoParameterswhole(str): Whole amount of NanoReturnsint, that is raw amount of Nanoraw_to_whole (Function)Converts raw Nano to whole Nano (Cuts off at 2 decimal places)Parametersraw(int): Raw amount of NanoReturnsint, that is whole amount of Nano