8.png
2023-07-08

everPay Python SDK Documentation

The Arweave Asia Summer Hackathon, co-hosted by PermaDAO, SCPVenture, and TintinLand, has officially begun and is now open for registration! To enable developers to seamlessly develop on Arweave, we will be sharing a series of user-friendly development tools. In this edition, we will introduce the everPay Python SDK.

The everPay Python SDK is an officially maintained lightweight Python SDK that serves as a tool library for accessing the everPay API. The source code is available on the GitHub repository. The main purpose of the Python SDK is to assist Python developers in quickly utilising the everPay protocol for development and serve as a supplementary integration tutorial for everPay.

Install Python SDK

  • Install via pip

  • pip install everpay

Set up wallet

everPay supports Ethereum and Arweave wallets for transactions.

import everpay #everPay provides a test environment 'https://api_dev.everpay.io' api_server = '<https://api.everpay.io>' #Set up the private key of the Ethereum wallet account pk = '' signer = everpay.ETHSigner(pk) account = everpay.Account(api_server, signer) #Set up an Arweave wallet account signer = everpay.ARSigner('arweave-keyfile-xxx.json') account = everpay.Account(api_server, signer)

Query everPay related information

Support queries for the following information

  • Summary of basic information about the everPay protocol, including lock-up addresses and supported tokens.

  • List of tokens supported by the everPay protocol.

  • Labels for tokens supported by the everPay protocol and native chain information related to the assets. In some occasions, two tokens may have the same name. For example, the USDC token bridged from Ethereum and the USDC token bridged from BSC both have the same token name as "USDC". In such cases, you should use the label to differentiate between the two tokens.

  • Query for account asset information.

Please provide the address and token name as parameters for the query.

import everpay api_server = '<https://api.everpay.io>' client = everpay.Client(api_server) #Query the basic information of the everPay protocol, including lock-up address, supported tokens and other information info = client.get_info() #Query the list of tokens supported by the everPay protocol support_tokens = client.get_support_tokens() #everPay protocol supports the labeling of tokens and related asset issuance protogenesis chain information token_list = client.get_token_list() #Account asset information query ar_balance = client.get_balance('0x5609FEc21fa681369e742994ca5D88B034D98E2F', 'ar')

Transfer transactions

The transfer method of everPay Python SDK can send transfer request. For each transfer, the following parameters need to be provided:

  • Tokens for making transfers

  • Payment address

  • Transfer amount

import everpay api_server = '<https://api.everpay.io>' #Demo with Ethereum Wallet private_key = '' signer = everpay.ETHSigner(private_key) account = everpay.Account(api_server, signer) #Token decimals can be obtained in the get_info function t, result = account.transfer('usdt', '0x911F42b0229c15bBB38D648B7Aa7CA480eD977d6', 10**6) #t.ever_hash Query transfer hash, result query transfer status print(t.ever_hash) print(result)

Bundle Transactions

Bundle transactions and batch transfers extend the functionality of the 'transfer' transaction. They include external transfers with the existing 'transfer' functionality and internal batch transfers achieved through a specific data field.

The data field contains multiple internal transfer transactions, as well as the signature of the account for all transfer transaction information. All internal transfers within the data field must succeed; if one fails, all internal transfers will roll back. A bundle transaction can only be executed once and cannot be executed again, regardless of the success or failure of the internal transfers.

Using bundle transactions, you can build additional functionalities such as decentralised exchanges, allowing the exchange of multiple types of tokens within a single transaction. You can leverage the features of bundle transactions to create more products.

#required library import uuid, time, json import everpay from everpay import BundleData, BundleItem #generate a universally unique identifier ( Universally Unique Identifier ), It guarantees uniqueness in space and time for all UUIDs. def create_uuid(): return str(uuid.uuid4()) #Set account-related information. In all internalItem internal transfer transactions, the everPay account corresponding to from needs to sign the bundle information. api_server = '<https://api.everpay.io>' private_key = '' signer = everpay.ETHSigner(pk) account = everpay.Account(api_server, signer) #Send wallet address, receive wallet address address_send = '0x5609FEc21fa681369e742994ca5D88B034D98E2F' address_receive = '0x3B11426d351A63Ba75F3bb87870c2ae5C8F32bf3' #bundle first transaction in transaction bundle_item = BundleItem('ar', '3', address_send, address_receive, str(3*10**11) ) #Create bundle_data,bundle transaction needs to include items、expiration、salt、version 四个参数。 #item,consists of multiple internal transfer transactions #expiration,expiration time for all internal transfer transactions, unix timestamp. Note: non-millisecond timestamp #salt,uuid format string for unique identification #version,Bulk transfer version, now all use 'v1' bundle_data = BundleData(bundle_item, int( time.time() + 100), create_uuid(), 'v1') #Add a second transaction to the bundle transaction bundle_item2 = BundleItem('usdt', '1', address_send, address_receiver, str(10**6) ) bundle_data.add_item(bundle_item2) #Sign the bundle transaction bundle_data.sign(address_send, private_key) #Send transaction t, result = account.bundle('ar', address_send, 0, bundle_data.get_data()) #Transaction hash and transaction status of external transfers print(t.ever_hash) print('post status:', json.loads(result)['status']) time.sleep(0.2) #Internal Transfer Status result = account.get_tx(t.ever_hash) print('internal_status:', result['tx']['internalStatus'] )

Note

  • If you encounter any issues while using the SDK documentation, please feel free to refer to the source code or seek assistance from the official admin on Discord.

  • everPay provides a testing environment at 'https://api_dev.everpay.io'. You can obtain some test tokens from the testnet faucet at https://faucet-dev.everpay.io/.

Sign up for newsletter

Sign up here to get the latest news and updates delivered directly to your inbox.