Encode a url

Encode a Solana Pay URL.

def encode_url(data: TransactionRequestURLParams | TransferRequestURLParams)
copy

Parameters

data: TransactionRequestURLParams | TransferRequestURLParams

Data to encode into a transaction request URL or transfer request URL

Returns encoded url string with data

Example

from solathon.solana_pay import encode_url
from solathon import Client, Keypair, PublicKey
label = "Jungle Cats store"
message = "Jungle Cats store - your order - #001234"
# Using transfer fields
client = Client("https://api.devnet.solana.com")
recipient = PublicKey("mvines9iiHiQTysrwkJjGf2gb9Ex9jXJX8ns3qwf2kN")
reference = Keypair().public_key
amount = 0.01
url: str = encode_url({"recipient": recipient, "label": label, "message": message,
"amount": amount, "reference": reference})
# Using link
link = "https://www.example.com"
url: str = encode_url({"link": link, "label": label, "message": message })
copy

The complete example code can be found here.