A customer buys a 1 USDC sticker from a demo shop: the customer pays, the
shop’s server checks the payment onchain, and only then is the order paid.
Press Run to step through this tutorial’s code on a local test network
(Surfpool). Nothing is sent from your browser, and no real money moves.
Demo Sticker ShopLocal test network (Surfpool)
Holographic sticker1.00 USDCNot paid yetPayment sent · not verified yetPaid · ready to ship
- The customer pays 1 USDC The order asks for 1,000,000 base units (1 USDC) and carries a fresh reference. The customer’s wallet approves one USDC transfer to the shop, and
payStorereturns the transaction’s signature. The shop hasn’t checked anything yet. - The shop’s server verifies the payment The checkout sends the signature to the shop’s server. The server fetches that transaction from the network and checks that it succeeded, carries the order’s reference, and moved exactly 1 USDC of the USDC mint into the shop’s account. Only then is the order paid.
# Step 1/2 · The customer pays 1 USDC
order
{
id:
'order-1001',storeOwner:
'DVxMtF9M6EAQ8CjqH9omYUTXdJU7hu4M8G94udRyr1m6',amount: 1000000n,
reference:
'47venn787GZLWUcgUU3QM1CpT11JHQMs8hyYQMPXKN2W'}
const signature = await payStore(customer, order)
signature
'paxK3zbseZEZpGrmGrzm3p3VYF5XN6aTAGKS1sVt2CmkcJ2afLCTB5C84rFT8VFX6LboNFty2pzcTCiVJw5DAtJ'Payment sent · not verified yet
# Step 2/2 · The shop’s server verifies the payment
await verifyPayment({ ...order, signature, mint: USDC_MINT }){ paid: true }
Verified: amount, mint, recipient, and reference
Verified. The shop’s server confirmed that 1 USDC for order-1001 reached the shop, so the order can ship.
What just happened
Step 1 is the customer’s side. The order and the approval became a transaction:amount: 1000000n. USDC has 6 decimals, so 1 USDC is 1,000,000 base units. Code always works in base units.storeOwner. The shop’s wallet. The USDC goes to the shop’s USDC account for that wallet.reference. A fresh address created for this order and attached to the transfer. The shop uses it to tell which order a payment is for.signature. The transaction’s ID, whichpayStorereturns once the network has confirmed the transfer. The checkout hands it to the shop’s server.
{ paid: true } only if it succeeded, carries the order’s reference,
and moved exactly 1 USDC of the USDC mint into the shop’s account. The shop
goes by the network’s record, not the customer’s word.
The 1 USDC did not move between the two wallets directly. It moved from the
customer’s USDC account to the shop’s USDC account:
What a wrong amount looks like
The same check refuses a payment that doesn’t match the order. Here the 1 USDC payment from above is checked against an order that costs 2 USDC:What a wrong amount looks likeLocal test network (Surfpool)
await verifyPayment({ ...order, amount: 2_000_000n, signature, mint: USDC_MINT }){
paid: false,
reason:
'amount mismatch: expected 2000000, received 1000000'}
Refused: amount mismatch