Wallet Integration
StreamPay Wallet Providers
This section describes how a wallet provider can support payment links in StreamPay app. It shows how to parse the payment URL and create a transaction from it.
This guide walks through an example implementation for wallet providers. The purpose of this is to make it easy for wallets to implement the protocol correctly.
1. Set up StreamPay Wallet
Install the packages and import them in your code.
npm
npm install @stream-pay-wallet @stream/web3.js --save
yarn
yarn add @stream-pay-wallet @stream/web3.js
2. Parse payment request link
As a wallet provider, you will have to parse the received URL to extract the parameters. For more information on the URL format, please see the specification.
3. Create transaction
Use the createTransaction
function to create a transaction with the parameters from the parseURL
function with an additional payer
.
The payer
should be the public key of the current users' wallet.
This transaction should represent the original intent of the payment request link. The example implementation walks through the steps on how to construct the transaction:
Native STRM/SOL transfer
Check that the payer and recipient accounts exist
Check the payer and recipient are valid native accounts
Check the payer has enough lamports for the transfer
Create an instruction to transfer native STRM or SOL
If references were included, add them to the instruction
If a memo was included, create an instruction for the memo program
SPL token transfer
Check that the payer and recipient accounts exist
Check the token provided is an initialized mint
Check the payer and recipient's Associated Token Account (ATA) exists
Check the payer has enough lamports for the transfer
Create an instruction to transfer SPL tokens
If references were included, add them to the instruction
If a memo was included, create an instruction for the memo program
4. Complete transaction
With the transaction formed. The user must be prompted to approve the transaction.
The label
and message
should be shown to the user, as it gives added context to the user on the transaction.
Deep linking
Wallet providers building for mobile or wearable devices are encouraged to register their app as a handler for the StreamPay URL schemesolana:
.
For example, when a payment request is presented as a QR code, the payer should ideally be able to read the code using the native scanning capability of their device and have the appropriate wallet open with the transaction prefilled.
URLs can be embedded in the environment in web pages, QR codes, NFC tags and potential new formats. To avoid inadvertent transfer of tokens, care must be taken when designing wallets to ensure that transactions cannot accidentally be triggered and sent.
Last updated