Package: upvest
Upvest Python SDKInstallationThe Upvest SDK is available onPYPI. Install with pip:pipinstallupvestThe default SDK is lightweight, and user recovery kits are returned as an SVG in string format. If you wish to process the recovery kit in binary format, then additional requirements are necessary:pipinstallupvest[recovery]Note that this may require additional system level dependencies to supportPyNaCl.DocumentationIn order to retrieve your API credentials for using this Python client, you'll need tosign up with Upvest.API Keys AuthenticationThe Upvest API uses the notion oftenants, which represent customers that build their platform upon the Upvest API. The end-users of the tenant (i.e. your customers), are referred to asclients. A tenant is able to manage their users directly (CRUD operations for the user instance) and is also able to initiate actions on the user's behalf (create wallets, send transactions).The authentication via API keys and secret allows you to perform all tenant related operations.
Please create an API key pair within theUpvest account management.The defaultBASE_URLfor both authentication objects ishttps://api.playground.upvest.co, but feel free to adjust it, once you retrieve your live keys.
Next, create anUpvestTenancyAPIobject in order to authenticate your API calls:fromupvest.tenancyimportUpvestTenancyAPItenancy=UpvestTenancyAPI(API_KEY,API_SECRET,API_PASSPHRASE,base_url=BASE_URL)# or base_url=None to use the playground environment (default)OAuth AuthenticationThe authentication via OAuth allows you to perform operations on behalf of your user.
For more information on the OAuth concept, please refer to ourdocumentation.
Again, please retrieve your client credentials from theUpvest account management.Next, create anUpvestClienteleAPIobject with these credentials and your user authentication data in order to authenticate your API calls on behalf of a user:fromupvest.clienteleimportUpvestClienteleAPIclientele=UpvestClienteleAPI(CLIENT_ID,CLIENT_SECRET,username,password,base_url=BASE_URL)# or base_url=None to use the playground environment (default)API CallsAll tenancy related operations must be authenticated using the API Keys Authentication, whereas all actions on a user's behalf need to be authenticated via OAuth. The API calls are built along with those two authentication objects.The methods allow for passing parameters if needed. If the required arguments are not provided, a respective error will be raised.Response objectsThe response objects are designed around users, wallets, transactions and assets. If you retrieve more than one object (for example:tenancy.users.all()) a list of those objects will be returned.User objectThe user response object has the following properties:user=tenancy.users.get('username')user.usernameuser.recoverykit# is None if not just createdWallet objectThe wallet response object has the following properties:wallet=clientele.wallets.get('wallet_id')wallet.transactionswallet.idwallet.balanceswallet.protocolwallet.addresswallet.statusAsset objectThe transaction response object has the following properties:asset,*rest=clientele.assets.all()asset.idasset.nameasset.symbolasset.exponentasset.protocolasset.metadataTransaction objectThe transaction response object has the following properties:transaction=wallet.transactions.get('transaction_id')transaction.idtransaction.pathtransaction.hashtransaction.sendertransaction.recipienttransaction.quantitytransaction.feetransaction.statusUsageTenancyUser managementCreate a useruser=tenancy.users.create('username','password')Retrieve a useruser=tenancy.users.get('username')List all users under tenancyusers=tenancy.users.all()List a specific number of users under tenancyusers=tenancy.users.list(10)Change password of a useruser=tenancy.users.get('username').update(password='current_password',new_password='new_password')Delete a usertenancy.users.get('username').delete()ClienteleAssetsList available assetsassets=clientele.assets.all()Note that it's also possible to retrieve the same list fromtenancy.assets.all().WalletsCreate a wallet for a userwallet=clientele.wallets.create('asset_id','password')Retrieve specific wallet for a userwallet=clientele.wallets.get('wallet_id')List all wallets for a userwallets=clientele.wallets.all()List a specific number of walletswallets=clientele.wallets.list(40)TransactionsCreate transactionwallet=clientele.wallets.create('asset_id','password')transaction=wallet.transactions.create('password','asset_id','quantity','fee','recipient')Retrieve specific transactionwallet=clientele.wallets.create('asset_id','password')id=wallet.transactions.all()[i].idtransaction=wallet.transactions.get(id)List all transactions of a wallet for a userwallet=clientele.wallets.create('asset_id','password')transactions=wallet.transactions.all()List a specific number of transactions of a wallet for a userwallet=clientele.wallets.create('asset_id','password')transactions=wallet.transactions.list(8)UsageTenant creationThe business "Blockchain4Everyone", founded byJohn, would like to build a platform for Ethereum wallets with easy access and wallet management. Therefore, John visits theUpvest Signup Page, creates an account, and retrieves his API keys from the account management page. He is now able to create the API Keys Authentication object:# API Keys objectfromupvest.tenancyimportUpvestTenancyAPItenancy=UpvestTenancyAPI(API_KEY,API_SECRET,API_PASSPHRASE,base_url=BASE_URL)User creationJohn sets up his platform and soon has the first person signing up for his service. Jane Apple, his first user, creates an account entering the usernameJane Appleand the passwordvery secret. Via an API call from his application's backend to the Upvest API, John creates an account for Jane under his tenancy account with Upvest, by implementing the following call using the API keys object from before:user=tenancy.users.create('Jane Apple','very secret')recovery_kit=user.recovery_kitAfter the request, John can access the recovery kit in the user instance and pass it on to Jane. Recovery kits are encrypted using a public key whose private counterpart is provided to tenants at sign-up on the Upvest Account Management portal, and not stored by Upvest. In case Jane loses her password, John is able to reset her password on her behalf, using her password and his decryption key, after conducting a proper KYC process in order to prevent identity fraud.Wallet creationAfter creating an account Jane wants to create an Ethereum wallet on John's platform. In order to do that on behalf of Jane, John needs to initialize an OAuth object with his client credentials and Jane's username and password. After doing so, John can easily create a wallet by providing the respectiveasset_idfor Ethereum to thewallets.create()function. Theasset_idcan be retrieved via a call to the Upvest asset endpoint, using the clientele or tenancy authentication:fromupvest.clienteleimportUpvestClienteleAPIclientele=UpvestClienteleAPI(CLIENT_ID,CLIENT_SECRET,'Jane Apple','very secret',base_url=BASE_URL)# List assets and their idsasset_id=clientele.assets.all()[i].idasset_id=tenancy.assets.all()[i].id# Create a wallet for Jane on Ethereum with her password and the respective asset_idethereum_wallet=clientele.wallets.create(asset_id,'very secret')wallet_address=ethereum_wallet.addressUsing the address, Jane is now able to receive funds in her Ethereum wallet on John's platform. Thus she sends Ethereumfrom her current Ethereum wallet provider and sends the funds to her newly created wallet on John's platform.Transaction sendingAfter a couple of days, Jane would like to buy a new road bike, paying with Ether. The address of the seller is0x6720d291A72B8673E774A179434C96D21eb85E71and Jane needs to transfer 1 ETH. As a quantity it's denoted inWei(Ether's smallest unit), John will need to implement a transformation of this amount. The transaction can be sent via the Upvest API making the following call:# Retrieve Jane's wallet_idwallets_of_jane=clientele.wallets.all()wallet=wallets_of_jane[0]recipient='0x6720d291A72B8673E774A179434C96D21eb85E71'# Send the transactiontransaction=wallet.transactions.create('very secret','asset_id',1000000000000000000,4000000000,recipient)txhash=transaction.txhashThat's it! Jane has successfully sent a transaction and is able to monitor it viaEtherscan.