Create a QR Code

Create a QR code from a Solana Pay URL.

def create_qr(link: str, size: int = 10, background: str = 'white', color: str = 'black', border: int = 2)
copy

Parameters

link: str

link to encode.

size: int = 10

Width and height of the QR

background: str = 'white'

Background color, which should be light for device compatibility.

color: str = 'black'

Foreground color, which should be dark for device compatibility.

border: int = 2

Border width around the QR code

Returns image stream in the form of BytesIO

Example

from solathon.solana_pay import create_qr
# using encoded transfer request fields
url = "solana:mvines9iiHiQTysrwkJjGf2gb9Ex9jXJX8ns3qwf2kN?amount=1e-09&label=Jungle+Cats+store&message=Jungle+Cats+store+-+your+order+-+%23001234&memo=JC%234098&reference=6DgHPm8gQp2mvQs5wuYTbJCH5KkkdJ7i4P76M31aegCQ"
qr_image = create_qr(url)
# Saving to a file
with open("qr.png", "wb") as f:
f.write(qr_image.getvalue())
# Rendering on a webserver or sending through API using Flask | Django | FastAPI
@app.route('/render_image')
def render_image():
qr_image.seek(0)
return send_file(img_bytes_io, mimetype='image/png')
copy

The complete example code can be found here.