Crypto Native Tap to Pay Between Mobile, Wearables and POS
A Solana smart contract built with the Anchor framework that enables tap-to-pay functionality for token payments.
- Token Authorization: Users can authorize tokens (e.g., USDC) to be spent by the contract
- Merchant Whitelisting: Contract owners can whitelist merchant addresses
- Secure Payments: Only authorized owners can trigger payments from users to merchants
- User Control: Tokens remain in the user's wallet until payment is processed
The contract uses Program Derived Addresses (PDAs) to store various states:
- Program Config: Stores the contract authority (deployer)
- Owner Accounts: Stores owner addresses that have admin privileges
- Merchant Accounts: Stores whitelisted merchant addresses
- Payment Auth: Stores the amount of tokens a user has authorized for payments
- Solana CLI tools
- Anchor Framework
- Node.js and npm/yarn
- Rust and Cargo
-
Clone the repository:
git clone https://github.com/yourusername/rozo-tap-to-pay.git cd rozo-tap-to-pay
-
Install dependencies:
npm install
-
Generate Solana accounts (deployer and user):
npm run generate-accounts
This script will:
- Generate Solana keypairs for deployer and user
- Save them to the
keys/
directory - Create a
.env
file with the paths to these keypairs
-
Fund your accounts with SOL (on devnet):
npm run fund-accounts
This requires the Solana CLI to be installed and will airdrop SOL to your accounts on devnet.
-
Build the program:
npm run build
Run the test suite:
anchor test
- Update the program ID in
Anchor.toml
andlib.rs
with your own if needed - Set up your Solana wallet and ensure it has SOL for deployment
- Run the deployment script:
npm run deploy:mainnet
To authorize tokens for payment:
yarn authorize <token_mint_address> <amount>
Example:
yarn authorize EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v 10
This authorizes 10 USDC (assuming the provided address is USDC) for payments.
Admin operations:
-
Add an owner:
yarn admin add-owner <owner_public_key>
-
Add a merchant:
yarn admin add-merchant <merchant_public_key>
-
Process a payment:
yarn admin process-payment <user_public_key> <merchant_public_key> <token_mint_address> <amount>
Example:
yarn admin process-payment 7KBVGvotfYJwfKJzAfEY5jabbus3MsZTGiALWi67L8Y2 Hm1rJ4DmXZMxXFMPuieeKGgMUJaZ6r7AzWhtKbg94pTY EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v 3
This processes a payment of 3 USDC from the user to the merchant.
- The contract ensures only authorized owners can add merchants and process payments
- Users maintain control of their tokens until a payment is processed
- Tokens remain in the user's wallet until a specific payment is authorized and processed
- Only whitelisted merchants can receive payments
Create a .env
file with the following variables:
# For deployment
DEPLOYER_KEYPAIR_PATH=/path/to/deployer_keypair.json
# For user operations
USER_KEYPAIR_PATH=/path/to/user_keypair.json
# For admin operations
ADMIN_KEYPAIR_PATH=/path/to/admin_keypair.json
- Initialization: The deployer initializes the contract and becomes the authority
- Add Owners: The authority adds owners to the contract
- Add Merchants: Owners add merchants to the whitelist
- User Authorization: Users authorize tokens for payments
- Payment Processing: Owners trigger payments from users to merchants