NEW

CCIP is now live for all developers. See what's new.

Back

Solana Pricefeeds Showcase

Learn how to deploy a Price Feeds app for Solana.

Overview

You can use onchain Chainlink Data Feeds to demonstrate how to build a simple prediction game using Solana.

Objective

This tutorial shows you how to install and configure the Solana Prediction Game locally so you can learn from this example and build your own applications on Solana that use Chainlink Data Feeds. You will set up your Solana environment, configure Vercel, and configure a MongoDB database.

Before you begin

  1. Install [Node.js 14 or higher][node.js-url]. Run node --version to verify which version you have installed:

     node --version
    
  2. Set up yarn package manager.

    npm i -g yarn
    
  3. Set up gh on your machine

    npm install -g gh
    
  4. Fork and clone the repo

    gh repo fork https://github.com/smartcontractkit/solana-prediction-game.git --clone
    
  5. Set up Solana CLI

  6. Run solana --version to make sure the Solana CLI is installed correctly.

      solana --version
    
  7. Set up Vercel

    1. To install the latest version of Vercel CLI, run this command:

      npm i -g vercel
      
    2. To quickly start a new project, run the following commands:

      cd solana-prediction-game    # Change directory to the project
      vercel          # Deploy to the cloud
      
    3. Connect your Git repository to Vercel and deploy with git push.

  8. Set up a Solana wallet. For this example, install the Phantom wallet:

    1. Visit https://phantom.app/download and select your browser type. Follow the steps in your respective extension store to add Phantom to your browser. After installing, you should see Phantom start-up in a new tab.
    2. If you are a brand new Solana user, select "Create New Wallet" and create a password. If you are an existing Solana user, you can follow the steps here to migrate your existing wallets to Phantom.
    3. Store your "Secret Recovery Phrase" in a safe and secure location, it is the only way to recover your wallet. Whoever has access to this phrase has access to your funds.
  9. Set up Phantom mobile app.

    1. Visit https://phantom.app/download and select the app marketplace according to your device type (iOS/Android). You will be redirected to the Phantom application on your device app store, follow the steps to download and install the application on your device. After installing, open the app and you should see the Phantom onboarding screen to set up a new wallet.
    2. If you are a brand new user, select "Create a new wallet" and enable the device authentication (which may vary according to the device type) to protect your wallet from unauthorized access. If you are an existing Solana user, you can select "I already have a wallet" and enter your seed phrase to restore your wallets.
    3. You can add additional security, e.g: enabling bio-metric security or face recognition, in Settings (Upper left corner), Security & Privacy.
  10. Switch to Solana Devnet

  11. Open your Phantom Wallet, click on the gear icon in the bottom right-hand corner, scroll to Change Network and click on Devnet.

  12. Airdrop yourself Devnet Solana Tokens.

  13. Open the faucet: https://solfaucet.com/

  14. Copy your Phantom Wallet address

  15. Paste your wallet address into the text field and then click 'DEVNET' to send the Solana token

  16. Switch your network to devnet on your wallet.

Steps to implement

1 Configure the application
  1. Change to the project directory cd solana-prediction-game

  2. Run cp .env.example .env

  3. Install the NPM packages

    yarn
    
  4. Download a wallet extension on your browser, preferably Phantom. Follow the instructions to set up your wallet.

  5. You need an Escrow account to hold and pay out Solana to your users. There are two ways to acquire this:

    1. Copy your private key from your Wallet. In this example, we will be using Phantom.
      1. Open the Phantom browser extension menu
      2. Create a new account
      3. Select the menu and pick Security and Privacy
      4. Then Export Private Key
      5. Enter your password.
      6. Copy the contents to WALLET_PRIVATE_KEY= in .env
    2. Create a temporary Solana wallet via solana-keygen. Alternatively, if you have an existing wallet that you want to use, locate the path to your [keypair][keypair-url] file and use it as the keypair for the rest of this guide.
        solana-keygen new --outfile ./id.json
      
      Copy the contents of the array in ./id.json to WALLET_PRIVATE_KEY= in .env
2 Set up a MongoDB database
  1. Set up a MongoDB account via the following tutorial: Create MongoDB Account.

  2. Set up MongoDB cluster. Create Cluster

  3. Set up MongoDB User. Create User Users Page Create User

  4. Get the MongoDB Connection URI.

    1. Navigate to the Database Deployments page for your project.
    2. Click the Connect button. Connect
    3. Select Connect your application Connection String
    4. Copy the connection URI string to MONGODB_URI= in your .env. URI string
    5. Replace the <user> and <password> to your MONGODB_URI with the username & password you created. MONGODB_URI
  5. Configure your Network Connection for your local development and deployment

    • For Local development.

      1. On the left sidebar of your screen select Network Access
      2. Click on Add IP Address.
      3. Click Add My Current IP Address.
      4. Click Confirm and your IP address is added to the list of addresses.
    • For Vercel deployment.

      1. On the left sidebar of your screen select Network Access.
      2. Click on Add IP Address.
      3. In the box labeled Access List Entry add 0.0.0.0/0.
      4. In the box labeled Required for your Cluster(s) linked to Vercel add Required for your Cluster(s) linked to Vercel.
      5. Click Confirm and your IP address is added to the list of addresses.

      Network Access

3 Run the example
  1. Generate a random API key here and copy it to API_SECRET_KEY=.

  2. Run the following command to start the application:

    yarn development
    

You can access the app at the URL provided by Vercel.

UI Screenshot

Stay updated on the latest Chainlink news