Package: bananopie
BananopieBananopie is a python library for the Banano cryptocurrency. It aims to be the python equivalent of Banano.js, and not just a RPC wrapper (Sending, receiving, changing rep functions are very high level).Installationpip install bananopieBananopie is onpypi.NotesThere is an outdated fork of Bananopie for Nano, also made by me, callednanohakase. It should suit most of your needs, but if you need new Bananopie features, fork Bananopie, change the work difficulty toFFFFFFF800000000, decimals to31, and you should be good to go.When running on Replit (ew), installing Bananopie may fail if you do not havegccinstalled (nix package:libgccjit).Quick StartFirst, start with aRPCclass, for read onlyfrombananopieimport*rpc=RPC("https://kaliumapi.appditto.com/api")#check current blockcountprint(rpc.get_block_count()["count"])#get last 10 transactions of JungleTVprint(rpc.get_account_history("ban_1jung1eb3uomk1gsx7w6w7toqrikxm5pgn5wbsg5fpy96ckpdf6wmiuuzpca",count=10)["history"])#check balance of JungleTVprint(raw_to_whole(int(rpc.get_account_balance("ban_1jung1eb3uomk1gsx7w6w7toqrikxm5pgn5wbsg5fpy96ckpdf6wmiuuzpca")["balance"])))For sending/receiving transactions, use aWallet.frombananopieimportRPC,Walletrpc=RPC("https://kaliumapi.appditto.com/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 banano to the faucet development fundprint(my_account.send("ban_3pdripjhteyymwjnaspc5nd96gyxgcdxcskiwwwoqxttnrncrxi974riid94","1"))#receive fundsmy_account.receive_all()#change repmy_account.change_rep("ban_3catgir1p6b1edo5trp7fdb8gsxx4y5ffshbphj73zzy5hu678rsry7srh8b")#change seed indexmy_account.index=2Bananopie can also generate work, albeit slowly. This is useful when using node that don't support generating work. Also, thelegacyparameter can be passed to the RPC class when the RPC supports the deprecatedpendingRPC call instead of the newerreceivablecall.frombananopieimportRPC,Walletno_work_rpc=RPC("https://public.node.jungletv.live/rpc",legacy=True)my_work_account=Wallet(no_work_rpc,seed="seed here",index=0,try_work=True)#will generate work locally!my_work_account.send("ban_3pdripjhteyymwjnaspc5nd96gyxgcdxcskiwwwoqxttnrncrxi974riid94","0.0042")Utility functions are also provided.importbananopie#whole to raw bananoprint(bananopie.whole_to_raw("492.2"))#raw to whole bananoprint(bananopie.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 headerlegacy(bool, Default: False): IfTrue, will use 'pending' instead of 'receivable'Sample:rpc=RPC("https://kaliumapi.appditto.com/api")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(list[str]): List of block hashes to get information onReturns:SeeNano RPC Docsget_blocks_info (Function)Get blocks, with more detailed information.Parametersblocks(list[str]): 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 allowhead(strorNone, Default: None): Block hash to start from, defaults to latest block hash if omittedaccount_filter(list[str]orNone, Default: None): List of addresses to only show sends/receives from. Please note that some public nodes will ignore this parameterReturns: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(list[str]): 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 returnthreshold(intorNone, Default: None): Optional parameter to filter out any receivable transactions with value below the threshold (in raw)Returns:SeeNano RPC DocsWallet (class)Parameters:rpc(RPC): A RPC classseed(strorNone, Default: None): 64 character hex seed, ifNone, 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.try_work(bool, Default: False): IfTrue, will try to generate work locally instead of asking node for work (and no work provided). Good to use if node does not support generating own work.Sample:my_wallet=Wallet(RPC("https://kaliumapi.appditto.com/api"),"seed here",0)Properties:rpc_url(str): IP or URL of nodeseed(str): Banano 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 BananoParametersto(str): Address to send toamount(str): Amount of Banano to send (in whole, not raw)work(strorbool, Default: False): Leave it asFalseto ask node to generate work (passesdo_work). Put in a work string if work generated locallyprevious(strorNone, Default: None): Previous block hash. Otherwise, address' frontier block hash usedSample:my_wallet=Wallet(RPC("https://kaliumapi.appditto.com/api"),"seed here",0)my_account.send("ban_3pdripjhteyymwjnaspc5nd96gyxgcdxcskiwwwoqxttnrncrxi974riid94","1")ReturnsSeeNano RPC Docssend_all (Function)High level function to send all BananoParametersto(str): Address to send towork(strorbool, Default: False): Leave it asFalseto ask node to generate work (passesdo_work). Put in a work string if work generated locallyprevious(strorNone, Default: None): Previous block hash. Otherwise, address' frontier block hash usedSample:my_wallet=Wallet(RPC("https://kaliumapi.appditto.com/api"),"seed here",0)my_account.send_all("ban_3pdripjhteyymwjnaspc5nd96gyxgcdxcskiwwwoqxttnrncrxi974riid94")ReturnsSeeNano RPC Docsreceive_specific (Function)Receive a specific blockParametershash(str): Block hash to receivework(strorbool, Default: False): Leave it asFalseto ask node to generate work (passesdo_work). Put in a work string if work generated locallyprevious(strorNone, Default: None): Previous block hash. Otherwise, address' frontier block hash usedReturnsSeeNano RPC Docsreceive_all (Function)Receive all (technically, 20) receivable transactionsParameterscount(int, Default: 20): Optional parameter to specify max amount of receivable transactions to receivethreshold(intorNone, Default: None): Optional parameter to not receive any receivable transactions with value below the threshold (in whole, not raw)Sample:my_wallet=Wallet(RPC("https://kaliumapi.appditto.com/api"),"seed here",0)my_account.receive_all()ReturnsA list of block hashes that were received (SeeNano RPC Docs)change_rep (Function)Change account representativeParametersnew_representative(str): Representative Banano 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 locallyprevious(strorNone, Default: None): Previous block hash. Otherwise, address' frontier block hash usedSample:my_wallet=Wallet(RPC("https://kaliumapi.appditto.com/api"),"seed here",0)my_account.change_rep("ban_3catgir1p6b1edo5trp7fdb8gsxx4y5ffshbphj73zzy5hu678rsry7srh8b")ReturnsSeeNano RPC Docssign_message (Function)Sign utf-8 message with private key at current index of current seedParametersmessage(str): utf-8 message to signReturnsstr, Hex signaturesign_message_dummy_block (Function)Sign utf-8 message as a dummy block (making sure ledger devices can also sign) with private key at current index of current seedParametersmessage(str): utf-8 message to signReturnsstr, Hex signatureget_public_key (Function)Get public key at current index of current seedParametersNoneReturnsstr, Hex public keyget_address (Function)Get address at current index of current seedParametersNoneReturnsstr, Banano 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_receivable_whole_threshold (Function)Double wrapped function to get receivable blocks (seeRPC'sget_receivable), exceptthresholdparameter is in whole Banano, not rawget_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)get_account_history (Function)Double wrapped function to get account info of self (seeRPC'sget_account_history)generate_seed (static Function)Generate a random seed usingos.urandomParametersNoneSample:print(Wallet.generate_seed())Returns64 character hex seedUtilPropertiesBANANO_DECIMALS(int): Amount of decimals that Banano has (29)PREAMBLE(str): Hex string to prepend when signingBANANO_WORK(str): Hex string of Banano's work threshold/minimumMethodsencode_base32,decode_base32,bytes_to_hex,hex_to_bytes,utf8_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,sign,sign_message_dummy_block,gen_dummy_block_hashare internal use Functions that are currently undocumented. Look at/bananopie/util.pyto see what they do.verify_message (Function)Verifies whether signed message is realParameterspublic_key(str): Hex public keysignature(str): Hex signatureclaimed_message(str): utf-8 message that was allegedly signedReturnsbool,Trueif message verified,Falseif message not verifiedverify_message_dummy_block (Function)Verifies whether signed message (with dummy block) is realParameterspublic_key(str): Hex public keysignature(str): Hex signatureclaimed_message(str): utf-8 message (with dummy block) that was allegedly signedReturnsbool,Trueif message (with dummy block) verified,Falseif message (with dummy block) not verifiedwhole_to_raw (Function)Converts whole Banano to raw BananoParameterswhole(str): Whole amount of BananoReturnsint, that is raw amount of Bananoraw_to_whole (Function)Converts raw Banano to whole Banano (Cuts off at 2 decimal places by default)Parametersraw(int): Raw amount of Bananoprecision(int, Default: 2): Decimal places to cut off atReturnsint, that is whole amount of Bananoraw_to_whole_no_round (Function)Converts raw Banano to whole Banano, without roundingParametersraw(int): Raw amount of BananoReturnsstr, that is unrounded whole amount of Bananogen_work_random (Function)Generate work given block's previous hash (or if opening block, account public key), and threshold. Generates work using psuedorandom generator.Parametershash(str): Hex previous hash of block / account public keythreshold(str): Hex minimum work thresholdReturnsstr, that is hex of workgen_work_deterministic (Function)Generate work given block's previous hash (or if opening block, account public key), and threshold. Generates work deterministically.Parametershash(str): Hex previous hash of block / account public keythreshold(str): Hex minimum work thresholdReturnsstr, that is hex of workgen_work (Function)Generate work given block's previous hash (or if opening block, account public key). Basically a wrapper forgen_work_deterministicwith threshold being the hardcoded Banano default.Parametershash(str): Hex previous hash of block / account public keyReturnsstr, that is hex of workverify_work (Function)Verify whether work is valid or not, given previous hash of block (or if opening block, account public key).Parametershash(str): Hex previous hash of block / account public keywork(str): Hex of workReturnsbool, whether the work is valid or not