The Algorand platform has an application programming interface (API) to enable users to create and share payment prompts via a URI or QR code. By default, the API sends two types of information to the URI: an algorand address and a payment amount. You can also return any other information you want, such as a payment amount, service, or exchange rate.
Algorand is a revolutionary new way of paying for things, using a mathematical algorithm to automatically create deterministic and non-counterfeitable tokens. Algorand payment URIs can be generated with a single line of code: https://algo.run/// . “” is the algorithm that is used to generate your Algorand payment URI, and “” is the amount of Algorand that you want to spend. Credit: http://www.alternativeway.us/
We have learned how to create and share stylized QR codes, but how can you create and share a payment prompt URI? That’s what this post will help you learn. We’ll walk you through how to create a payment prompt URI using Algorand’s example URI and show you how to use that URI to generate a stylized URI.
AlgorandKit
Swift library for easy interaction with the Algorand blockchain. Integrate this library to easily create and share payment request URIs and stylized QR codes from Algorand.
Requirements
- Xcode 12.0 or higher.
- iOS 13.0 or later.
Setting
The Swift package manager is a tool to manage the distribution of Swift code. It integrates with the Swift build system to automate the process of loading, compiling and linking dependencies. To integrate AlgorandKit into an Xcode project running Xcode 12, specify it under File > Swift packages > Add package dependencies….. specify : https://github.com/computerbluemonday/AlgorandKit Or manually add a dependency in Package.swift : .package(url : https://github.com/computerbluemonday/AlgorandKit, from : 1.1.0)
AlgorandURI
Utility to create the URI of the Algorand payment prompt according to the : https://developer.algorand.org/docs/reference/payment_prompts/ According to the specification, this URI is a standardized way for apps and websites to send requests and information via deeplinks, QR codes, etc. On iOS, these URIs can be managed by the official Algorand Wallet app to delegate transaction processing to Algorand : https://developer.algorand.org/articles/payment-prompts-with-algorand-mobile-wallet/ AlgorandURI is an immutable Swift structure that applies business logic rules by defining a interface during initialization. All URIs constructed with AlgorandURI must be semantically valid . (AlgorandURI does not check addresses or the validity of transactions). The object definition is suitable for quick visual inspection in the debugger, for example. B : ▿ AlgorandURI – uriScheme: algorand ▿ receiver: Receiver – Address : 4AOJ5QITUBWZGO4K5AF77H5GED5A4QDBB6DOQGI63QE2GU6KD2XNETBBJE ▿ Label: Supplemental – Some : Bob ▿ assetAmount: AssetAmount ▿ algo: 1 item – microAlgo’s: 50 ▿ note: Optional ▿ some: note ▿ read-only: 1 Item – xnote : Transmission A set of test cases is included to verify the regression.
Application examples
let algoURI = AlgorandURI( receiver : AlgorandURI.Receiver(address : 4AOJ5QITUBWZGO4K5AF77H5GED5A4QDBB6DOQGI63QE2GU6KD2XNETBBJE, label : Barclay), assetAmount : .algo(microAlgos : 100), note : .readonly(xnote : Transporter Insurance)) let asaURI = AlgorandURI( receiver : AlgorandURI.Receiver(address : 4AOJ5QITUBWZGO4K5AF77H5GED5A4QDDBB6DOQGI63QE2GU6KD2XNETBBJE, label : Lanel), assetAmount : .ASA(assetID : 1000000, amount : 150), note : .readonly(xnote : Spaceship) if let url = algoURI.url() { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options : [ :], completionHandler : nil) } }
AlgorandQRCode
Utilities to generate raw and stylized QR codes from AlgorandURI instances:
- AlgorandURI (extension) — Generates a raw UII QR code image from AlgorandURI
- AlgorandQRCodeBadge — Creates a scalable Algorand QR code icon, (optionally) styled and tagged in SwiftUI.
Although not part of this library, see AlgorandQRCodeTests for examples of Algorand QR code recognition using the Apple vision framework.
Application examples
// Create AlgorandURI for the Barclay receiver for 100 microalgo, with note readonly Transporter Insurance let algoURI = AlgorandURI( receiver : AlgorandURI.Receiver(address : 4AOJ5QITUBWZGO4K5AF77H5GED5A4QDBB6DOQGI63QE2GU6KD2XNETBBJE, label : Barclay), assetAmount : .algo(microAlgos : 100), note : .readonly(xnote : Insurance carrier)) // Generate a raw UII QR code image for this URI transaction let qrCodeImage = algoURI.generateQRCode() // Instantiate a stylized QR code icon SwiftUI AlgorandQRCodeBadge( uri:AlgorandURI(receiver : AlgorandURI.Receiver(address : 4AOJ5QITUBWZGO4K5AF77H5GED5A4QDBB6DOQGI63QE2GU6KD2XNETBBJE, label : null), assetAmount : null, note : null), qrCodeColor : UIColor.systemTeal, frameConfiguration : .framed(color : UIColor.darkGray), includeLogo : true)
Example screenshots
UIActivityViewController / AirDrop
Support for sharing the AlgorandURI with other devices or services via UIActivityViewController. A range of exchange directions including AirDrop, SMS, Mail, Copy/Paste is defined by default; configurable by the caller for other exchange directions.
Application examples
// we create AlgorandURI for the data receiver for 400 microalgo. let algoURI = AlgorandURI( receiver : AlgorandURI.Receiver(address : 4AOJ5QITUBWZGO4K5AF77H5GED5A4QDBB6DOQGI63QE2GU6KD2XNETBBJE, label : Data), assetAmount : .algo(microAlgos : 400), note : .readonly(xnote : Catfood.) // Introduce UIActivityViewController to share algorandURI via AirDrop, SMS, etc. (SwiftUI) if let av = algoURI.activityViewController(excludedActivityTypes : nil) { UIApplication.shared.windows.first ?.rootViewController ?.present(av, animated : true, completion : nil) }
Example screenshots
AlgoSampleApp
AlgoSampleApp is a standalone iOS application project that demonstrates AlgorandKit import and specifically AlgorandURI support in UIActivityViewController / AirDrop. It can also be used as a test suite to explore other features of AlgorandKit. To build, open the AlgoSampleApp.xcodeproj file in the AlgoSampleApp folder.
GitHub
https://github.com/computerbluemonday/AlgorandKitAlgorand is an alternative to Bitcoin (BTC) that uses a Delegated Proof-of-Stake (DPoS) consensus algorithm. This will be the first in a series of posts discussing the advantages to using Algorand as the future of cryptocurrency.. Read more about algorand programming language and let us know what you think.
Related Tags:
algorand developeralgorand developer forumalgorand create tokenalgorand goalalgorand appsalgorand-sdk,People also search for,Privacy settings,How Search works,algorand developer,algorand developer forum,algorand create token,algorand developer rewards,algorand programming language,algorand goal,algorand grants,algorand award