Skip to content

Commit

Permalink
feat: initial web3-luzid implementation ready to deploy to gh-pages (#1)
Browse files Browse the repository at this point in the history
* feat: implement simple demo with luzid and web3 actions

* chore: readme and icons

* deps: upgrade luzid sdk

* prep: for gh-pages deploy

* ci: add deploy workflow
  • Loading branch information
thlorenz committed Jan 28, 2024
1 parent 1090b37 commit a686bdb
Show file tree
Hide file tree
Showing 24 changed files with 2,617 additions and 123 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Sample workflow for building and deploying a Next.js site to GitHub Pages
#
# To get started with Next.js see: https://nextjs.org/docs/getting-started
# See: https://github.com/gregrickaby/nextjs-github-pages?tab=readme-ov-file
name: Deploy Next.js site to Pages

on:
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: ${{ steps.detect-package-manager.outputs.manager }}

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}

- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./out

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"tabWidth": 2,
"arrowParens": "always",
"printWidth": 80
}
44 changes: 8 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Luzid: TicTacToe Example

## Getting Started
This example demonstrates how to interact with a Solana program inside the Luzid validator.

First, run the development server:
### Getting Started

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
1. Clone this repository
2. Run `yarn` inside of it
3. Run `yarn dev`
4. Launch Luzid

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Then have fun and play TicTacToe to understand how Luzid works!
176 changes: 176 additions & 0 deletions idl/tictactoe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"version": "0.1.0",
"name": "tic_tac_toe",
"instructions": [
{
"name": "setupGame",
"accounts": [
{
"name": "game",
"isMut": true,
"isSigner": true
},
{
"name": "playerOne",
"isMut": true,
"isSigner": true
},
{
"name": "systemProgram",
"isMut": false,
"isSigner": false
}
],
"args": [
{
"name": "playerTwo",
"type": "publicKey"
}
]
},
{
"name": "play",
"accounts": [
{
"name": "game",
"isMut": true,
"isSigner": false
},
{
"name": "player",
"isMut": false,
"isSigner": true
}
],
"args": [
{
"name": "tile",
"type": {
"defined": "Tile"
}
}
]
}
],
"accounts": [
{
"name": "Game",
"type": {
"kind": "struct",
"fields": [
{
"name": "players",
"type": {
"array": ["publicKey", 2]
}
},
{
"name": "turn",
"type": "u8"
},
{
"name": "board",
"type": {
"array": [
{
"array": [
{
"option": {
"defined": "Sign"
}
},
3
]
},
3
]
}
},
{
"name": "state",
"type": {
"defined": "GameState"
}
}
]
}
}
],
"types": [
{
"name": "Tile",
"type": {
"kind": "struct",
"fields": [
{
"name": "row",
"type": "u8"
},
{
"name": "column",
"type": "u8"
}
]
}
},
{
"name": "GameState",
"type": {
"kind": "enum",
"variants": [
{
"name": "Active"
},
{
"name": "Tie"
},
{
"name": "Won",
"fields": [
{
"name": "winner",
"type": "publicKey"
}
]
}
]
}
},
{
"name": "Sign",
"type": {
"kind": "enum",
"variants": [
{
"name": "X"
},
{
"name": "O"
}
]
}
}
],
"errors": [
{
"code": 6000,
"name": "TileOutOfBounds"
},
{
"code": 6001,
"name": "TileAlreadySet"
},
{
"code": 6002,
"name": "GameAlreadyOver"
},
{
"code": 6003,
"name": "NotPlayersTurn"
},
{
"code": 6004,
"name": "GameAlreadyStarted"
}
]
}
27 changes: 25 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
/**
* Enable static exports for the App Router.
*
* @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports
*/
output: 'export',

export default nextConfig;
/**
* Set base path. This is the slug of your GitHub repository.
*
* @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath
*/
basePath: '/ex-tictactoe.web',

/**
* Disable server-based image optimization. Next.js does not support
* dynamic features with static exports.
*
* @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized
*/
images: {
unoptimized: true,
},
}

export default nextConfig
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
"lint": "next lint"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@luzid/sdk": "^0.0.1",
"@solana/web3.js": "^1.89.1",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18",
"next": "14.1.0"
"react-simple-toasts": "^5.10.0"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.3.0"
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
}
Empty file added public/.nojekyll
Empty file.
Binary file modified public/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/vercel.svg

This file was deleted.

Loading

0 comments on commit a686bdb

Please sign in to comment.