Skip to content

Toy project to learn how to use the Solana Anchor framework.

Notifications You must be signed in to change notification settings

WangWilly/solana-poneglyph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Poneglyph

Toy project to learn how to use the Solana Anchor framework. (my notes 🐒)

Project Design (Ticket seller)

Current Issues with Ticket Selling

Solution

  • Create a decentralized ticket selling platform.
  • Tickets are sold as NFTs.
  • Tickets are minted by the organizer and sold to customers.
  • Tickets can be resold by customers and the organizer receives a commission.
  • Tickets can be verified by the organizer and the customer.
  • Tickets can be redeemed by the customer at the venue.

Flow

Components:

  • Organizer: Mints tickets and receives commissions.
  • Customer: Buys tickets and resells tickets.
  • Venue: Verifies tickets and redeems tickets.
Flow map 🗺️
graph TD
    A[Organizer] -->|Mint| B((Ticket))
    B -->|Sell| C[Customer]
    C -->|Resell| D[Customer]
    D -->|Sell| E[Customer]
    E -->|Redeem| F[Venue]
Loading
Sequence diagram 📈
sequenceDiagram

actor Organizer
participant organizer-hardware
participant server-APIs
participant Solana-contract
participant Solana-network
participant client-app
actor Customer

Organizer ->> server-APIs: Mint tickets request <br>ticket info: {number, price, date, venue, restrictions}
server-APIs ->> Solana-contract: Mint ticket request
Solana-contract ->> Solana-contract: Mint ticket
Solana-contract ->> Solana-network: SolAccount creation
Solana-network ->> Solana-contract: SolAccount creation response
Solana-contract ->> server-APIs: Mint ticket response <br>server can now sell tickets
server-APIs ->> client-app: Ticket sale
Customer ->> client-app: Buy ticket
client-app ->> server-APIs: Ticket sale request
server-APIs ->> Solana-contract: Transfer ticket request
Solana-contract ->> Solana-contract: Transfer ticket
Solana-contract ->> Solana-network: SolAccount update
Solana-network ->> Solana-contract: SolAccount update response
Solana-contract ->> server-APIs: Transfer ticket response
server-APIs ->> client-app: Ticket sale response
client-app ->> client-app: Ticket secured by client-app dynamically <br>(maybe using a 3-rd party service like Apple verify)
Customer ->> client-app: Resell ticket
client-app ->> server-APIs: Ticket resell request
server-APIs ->> Solana-contract: Transfer ticket request
Solana-contract ->> Solana-contract: Transfer ticket
Solana-contract ->> Solana-network: SolAccount update
Solana-network ->> Solana-contract: SolAccount update response
Solana-contract ->> server-APIs: Transfer ticket response
server-APIs ->> client-app: Ticket resell response
client-app ->> client-app: Ticket secured by client-app dynamically <br>(maybe using a 3-rd party service like Apple verify)
Customer ->> client-app: Use ticket
client-app ->> server-APIs: Ticket use request
server-APIs ->> Solana-contract: Redeem ticket request
Solana-contract ->> Solana-contract: Redeem ticket
Solana-contract ->> Solana-network: SolAccount update
Solana-network ->> Solana-contract: SolAccount update response
Solana-contract ->> server-APIs: Redeem ticket response
server-APIs ->> client-app: Ticket use response
client-app ->> organizer-hardware: Ticket verification
organizer-hardware ->> server-APIs: Ticket verification request
server-APIs ->> Solana-contract: Verify ticket request
Solana-contract ->> Solana-contract: Verify ticket
Solana-contract ->> Solana-network: SolAccount update
Solana-network ->> Solana-contract: SolAccount update response
Solana-contract ->> server-APIs: Verify ticket response
server-APIs ->> organizer-hardware: Ticket verification response
Loading

MVP

  • Organizer can mint tickets and sell tickets by setting the ticket price.
  • Customer can buy tickets and resell tickets limited to the ticket price.
  • Venue can verify tickets and redeem tickets.

Future Features

  • Organizer can set restrictions on tickets.
  • Customer can buy tickets in bulk.
  • Customer can resell tickets at a higher price. (?)

Setup

The rust toolchain is required to build the project. The following commands will install the rust toolchain and the required dependencies.

# Install the rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Installing using Anchor version manager

# Install the Anchor version manager
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force

# Install the build dependencies
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"

# Check the version of Anchor
solana --version

# Install the latest version of Anchor
avm install latest

# Check the version of Anchor
anchor --version

Build

# Build the project
./scripts/contract-build.sh

Test

Contract unit tests

https://developers.metaplex.com/core/helpers

./scripts/misc/set-metaplex-core.sh
./scripts/contract-test.sh

Backend integration tests (local)

On one terminal:

./scripts/misc/set-metaplex-core.sh
./scripts/misc/solana-local-dev-validator.sh

On another terminal:

./scripts/misc/new-sol-wallet.sh
./scripts/be-serve.sh dev

API

❶ Create a ticket:

curl --location 'localhost:3000/api/ticket/v1' \
--header 'Content-Type: application/json' \
--data '{
    "name": "test",
    "uri": "uri_test",
    "transfer_limit": 10
}'

Response:

{
    "asset_key": "xLZjdGZB3SdtUUYg4rKoBrVb9w7yFuKh8FNEBTzgCVB",
    "aes_gcm_tag": "21WlQQsekVvi0XSYH3iX8g=="
}

❷ Get the ticket:

curl --location 'localhost:3000/api/ticket/v1/xLZjdGZB3SdtUUYg4rKoBrVb9w7yFuKh8FNEBTzgCVB?aes_gcm_tag=21WlQQsekVvi0XSYH3iX8g%3D%3D'

Response:

{
    "name": "test",
    "owner": "79zjn9Pe3empMZZet5FHnNKaVjrLkCN9i2HV7u4THsVq",
    "uri": "uri_test2"
}

❸ Create an asset for the ticket:

curl --location 'localhost:3000/api/asset/v1' \
--header 'Content-Type: image/jpeg' \
--data-binary '~/Downloads/ED5FA0FF-DD05-48DE-AE0A-0701FB189A97.JPG'

Response:

{}

❹ Get the asset:

curl --location 'localhost:3000/api/asset/v1/image.jpg'

Milestones

Common Commands

solana config get # Get the current Solana cluster configuration
solana config set --url https://api.devnet.solana.com # Set the Solana cluster configuration
solana balance # Get the balance of the current wallet
solana airdrop 2 ~/.config/solana/id.json # Airdrop 1 SOL to the current wallet
solana address # Get the public key of the current wallet
solana keygen new --outfile ~/.config/solana/id.json # Generate a new keypair

solana transfer 1 [public-key] # Transfer 1 SOL to the specified public key
solana transfer --allow-unfunded-recipient 1 [public-key] # Transfer 1 SOL to the specified public key even if it's unfunded
solana transfer --allow-unfunded-recipient 1 [public-key] --from ~/.config/solana/id.json # Transfer 1 SOL from the current wallet to the specified public key even if it's unfunded

# https://docs.anza.xyz/cli/usage#solana-logs
solana logs --url localhost

# Initialize a new project
anchor init [new-workspace-name]