An illustration of the St. Petersburg Paradox built with React, Fastify, and Solidity.
infinite-odds/
├── client/ # React client application
│ ├── public/ # Static assets
│ ├── src/ # Source code
│ │ ├── api/ # API client
│ │ ├── components/ # React components
│ │ ├── contracts/ # Contract interactions
│ │ └── utils/ # Utility functions
├── server/ # Fastify server application
│ ├── api/ # Serverless function
│ │ └── serverless.js # Serverless function that Vercel uses
│ ├── src/ # Source code
│ │ ├── config/ # Configuration
│ │ ├── routes/ # API routes
│ │ └── server.js # Server entry point
│ │ └── local.js # Server entry point for local development
│ └── tests/ # server tests
└── contracts/ # Solidity smart contracts
├── src/ # Contract source code
└── test/ # Contract tests
- Clone the repository
- Install dependencies & copy .env files
# client
cd client
npm install
cp .env.example .env
# server
cd ../server
npm install
cp .env.example .env
# Smart Contracts
cd ../contracts
forge install
cp .env.example .env- Start the client and server services
cd client
npm run start # this will open a browser window
cd server
npm run startNote
Optionally, you can run the server in dev mode using vercel dev, which simulates
the serverless function.
Note
You can use the contract deployed on Tea Assam to test the game, or you can use forge to deploy your own contract.
Currently, tests are only defined for the server and the smart contract. Coverage isn't great, but always open to more.
# server tests
cd server
npm run test
# Smart contract tests
cd contracts
forge test- Push your code to GitHub
- Create a new project on Vercel
- Import your GitHub repository
- Configure environment variables in Vercel dashboard
- Deploy with the following settings:
- Framework Preset: Create React App
- Build Command:
npm run build - Output Directory:
build - Install Command:
npm install
- Create a
vercel.jsonin the server directory:
{
"version": 2,
"builds": [
{
"src": "api/serverless.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "api/serverless.js"
}
]
}-
Deploy using Vercel CLI:
cd server vercel
Important
I used different projects for the client and server, so had to select server as the
root directory.
- Configure environment variables in Vercel dashboard or using
vercel env add ENV_VAR
-
Deploy using Foundry:
cd contracts forge create src/InfiniteOdds.sol:InfiniteOdds \ --rpc-url $L2_RPC_URL \ --private-key $DEPLOYER_PRIVATE_KEY
-
Update the contract address in your server environment variables
Any PRs are welcome, but here's my personal list of stuff I'd like to see:
- testing
- non-crypto explanation of the paradox / SBF reference would be fun
- re-render game history on end
- better game history
- better focus on the current game elsewhere (use v0 for ideas)
- new game should reset all error messages
- store txn hashes?
- securely trigger
cashOut - move most of game logic here
- cashOut transactions result in token transfers, but not in the tea explorer...why?