This is a proof of concept of an NFT vending machine built using Solana Pay, Metaplex, Phantom Mobile, and Next.js

Overview

Solana NFT Vending Machine

This is a proof of concept of an NFT vending machine built using Solana Pay, Metaplex, Phantom Mobile, and Next.js. This was created and demoed at the 2022 Los Angeles Hacker House presented by Solana and FTX US.

This was created over the course of approximately 2 days and certainly puts the "hack" in Hacker House. This is intended as example code, please use caution if you plan on deploying this for anything "real".

Dependencies

Getting Started

Step 1: Install Dependencies

yarn install

Step 2: Set Environment Variables

This project uses Next.js' built-in environment variables support. Create a file named .env.local at the root of this repository. See .env.example for details on what to include in this file.

The environment variables are:

  • NEXT_PUBLIC_RPC_URL: The RPC server to connect to.
  • NEXT_PUBLIC_MERCHANT_WALLET_PUBKEY: The public key of the wallet that will receive transaction funds, mint NFTs, and be set as the update authority on the NFTs.
  • MERCHANT_KEYPAIR_PATH: The path to the keypair file of the merchant wallet.
  • NFT_COLLECTION_SIZE: The quantity of random NFTs to choose from when minting.
  • NFT_COLLECTION_PATH: The location of the directory that contains the on-chain JSON data files used to mint by Metaboss.
  • NEXT_PUBLIC_SOLANA_PAY_TRANSACTION_AMOUNT: How much to charge for the NFTs, leave blank to allow customers to name their own price.
  • NEXT_PUBLIC_SOLANA_PAY_TRANSACTION_LABEL, NEXT_PUBLIC_SOLANA_PAY_TRANSACTION_MESSAGE, and NEXT_PUBLIC_SOLANA_PAY_TRANSACTION_MEMO: Transaction metadata fields in the Solana Pay standard.

Step 3: Start the vending machine

Run yarn dev, then navigate to http://localhost:3000.

Overview of a Transaction

The overall lifecycle of a vending machine transaction consists of the following:

  1. A QR code is generated using the Solana Pay SDK that includes a reference ID based on a generated public key.
  2. The vending machine polls to check for an on-chain transaction that include the reference ID.
  3. Phantom Mobile is used to scan the Solana Pay QR code, which builds a transaction that is confirmed by the customer on their mobile device.
  4. The vending machine detects the transaction on-chain based on the reference ID, then begins polling to determine the validity and state of the on-chain transaction.
  5. Once the on-chain transaction is fully confirmed, the customer's wallet address is retrieved and is then used as the recipient when Metaboss is used to mint the NFT.
  6. The vending machine displays a success (or error) message to the customer, then generates a new QR code with a new reference ID and returns to the idle state.

Project Structure

Notable portions of this codebase include:

  • pages/index.jsx: The React page component that contains the majority of the UI and transaction polling / confirmation logic.
  • pages/api/mint.js: The API route that invokes Metaboss to mint an NFT.
  • components/: Miscellaneous UI components.
  • assets/: The NFT assets including images and both on- and off-chain metadata.

To Do

  1. Right now this handles the payment to the merchant and the minting of the NFT as two separate transactions. Ideally, this should be refactored to be a fully on-chain, atomic transaction that will automatically return funds to the customer in the event of a mint failure.
  2. Refactor assorted UI components to focus reusability and standardization.

Additional Resources

You might also like...
⛵️ A React library for Solana account management and transaction processing.

sail ⛵️ A React library for Solana account management and transaction handling. Usage import { SailProvider } from "@saberhq/sail";

Auth Service sample source. It supports Solana and EVM-compatiable chains

This repository is Auth Service sample source. It supports Solana and EVM-compatiable chains, more chains and more features coming soon! Learn more visit Particle Network.

_buildspace - web3 Read/Write Solana Blockchain Project
_buildspace - web3 Read/Write Solana Blockchain Project

_buildspace - web3 Read/Write Solana Blockchain Project

Solana Wallet Auth: A FullStack example
Solana Wallet Auth: A FullStack example

This example uses Solana's wallet adapter to sign messages and verifies their signatures on the backend, allowing for a lean way to authenticate users without the need for web2 credentials like email/password combinations or social providers, in this scenario all you have to do is connect your wallet and sign interaction messages to be properly authenticated.

NFT Marketplace prototype using Typescript, WalletConnect, Metamask, Web3, Solidity, React and Storybook

ERC721 NFT Marketplace Prototype of a NFT Marketplace based on openZeppelin abstract upgradeable ERC721 contracts and Minting/uploading images to IPFS

Ethereum nft marketplace template using react

ethereum-marketplace-template ⭐️ Star us If this boilerplate helps you build Ethereum dapps faster - please star this project, every star makes us ver

This is used for minting NFTs and getting metadata , token owner, wallet address assigned to an NFT, just check it out and enjoy

nft-minter A Heroku web server to easily mint non-fungible tokens via an API Example Configuration: Blockchain: Ethereum Testnet: Rinkeby Contract: ER

This Project is a fork of Ethereum Boilerplate and demonstrates how you can build your own NFT Rarity Ranker.
This Project is a fork of Ethereum Boilerplate and demonstrates how you can build your own NFT Rarity Ranker.

This Project is a fork of Ethereum Boilerplate and demonstrates how you can build your own NFT Rarity Ranker.

How to mint your own NFT token with react
How to mint your own NFT token with react

Mint your own basic off chain NFT Description This project teaches you how to mint your own NFT token. Here are some important packages that we will b

Comments
  • stderr Error: No such file or directory (os error 2) Directory Issues

    stderr Error: No such file or directory (os error 2) Directory Issues

    Having Issues getting it to work with my asset directory - Error: No such file or directory (os error 2)

    at ChildProcess.exithandler (child_process.js:383:12)
    at ChildProcess.emit (events.js:400:28)
    at ChildProcess.emit (domain.js:475:12)
    at maybeClose (internal/child_process.js:1058:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:400:28)
    at Socket.emit (domain.js:475:12)
    at Pipe.<anonymous> (net.js:686:12) {
    

    killed: false, code: 1, signal: null,

    what is the best way to find the directory path to input into my .env for ex mine is NFT_COLLECTION_PATH=/nft-vending-machine-main/assets/losangeles-hacker-house

    opened by walter-grace 4
  • Content Feature Enhancements

    Content Feature Enhancements

    Adds new content functionality and changes / cleans up a few things:

    • Adds heading, subhead, body copy content to main screen
    • Adds supported wallets component
    • Removal of unused assets
    • Replaced static image background with SVG gradient that also has an optional animated mode
    • Replaced logo header with MintStation logo
    • UI and Style updates
    opened by mattdeco 0
Owner
Matt Rosenzweig
Matt Rosenzweig
Code examples for the blog post titled The Complete Guide to Full Stack Solana Development with React, Anchor, Rust, and Phantom

The Complete Guide to Full Stack Solana Development with React, Anchor, Rust, and Phantom Code examples to go with the blog post available here Prereq

Nader Dabit 436 Dec 31, 2022
Proof of concept implementation of Suspense for Data Fetching for Apollo.

Apollo Query Result Proof of concept implementation of Suspense for Data Fetching for Apollo. WARNING! This is not a real package (yet)! Implementatio

null 10 Oct 7, 2022
React-fade: Proof of Concept react fade in/out that just works without any effort

react-fade Proof of Concept react fade in/out that just works without any effort. Inspired by react native layout animations. How it works FadeIn noth

Park June Chul 3 Nov 7, 2022
React-NFT-App - NFT-Web-Application built using Third web , ReactJs and use Crypto Punks with API

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Ali Aftab Sheikh 8 Oct 24, 2022
A drum machine built with React using the Create React App toolchain.

drum-machine A simple drum machine built with React using the Create React App toolchain. Getting Started Clone or download the repository. Open a com

Ryan Schafer 1 Dec 30, 2021
The ½ kb state machine hook for React

The ½ kb state machine hook for React

Cassio Zen 2.3k Dec 30, 2022
Quiz Machine - React Vite TypeScript

Quiz Machine - XState + React + Typescript + Vite Surge https://quiz-machine-react.surge.sh/ Github https://github.com/Krutie/quiz-machine-react-vite-

Krutie Patel 5 Sep 15, 2022
A simple Solana program to vote for your favorite type of peanut butter. Built with Anchor and React.

Cruchy vs Smooth V2 A simple Solana program to vote for your favorite type of peanut butter. Built with Anchor and React. This is a follow up to a pre

Brian Friel 45 Oct 12, 2022
A web application that allows you to create and share wall of gifs! Built on top of solana blockchain.

Wall of gif with Solana A web application that allows you to create and share wall of gifs! Built on top of solana blockchain. Installation and Usage

Sunrit Jana 4 Jan 1, 2022
Gif Portal build using solana, anchor, web3 and react

Features of the dapp View Popular Dance Moves Gifs Vote for your favorite Gifs Add link of your favorite dance gif on the portal All the data includin

Anshul Goel 5 Oct 27, 2022