Skip to content

Solana v2 #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ PUBLIC_API_URL=http://localhost:3000/api
# The public url used by clients to fetch assets
PUBLIC_ASSETS_URL=http://localhost:3000/assets


# LiveKit (voice chat)
LIVEKIT_WS_URL=
LIVEKIT_API_KEY=
LIVEKIT_API_SECRET=
LIVEKIT_API_SECRET=

# Solana World Wallet Keypair
WORLD_PUBLIC_KEY=
WORLD_PRIVATE_KEY=

# Solana World Token
WORLD_TOKEN_MINT_ADDRESS=8vBMibwpn8wpfYKbQ9xqzodymg3LjmYec2tSNGRy23K8

# Solana RPC
RPC_URL=
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
FROM node:22.11.0-alpine AS builder
WORKDIR /app

# Install Python and build tools
RUN apk add --no-cache python3 make g++ linux-headers eudev-dev

# Copy package.json and package-lock.json to leverage layer caching
COPY package.json package-lock.json ./
RUN npm install
Expand Down
52 changes: 52 additions & 0 deletions docs/solana.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Solana

## World Token

Your world accepts deposits and withdrawals of a specific token. This is specified with the `WORLD_TOKEN_MINT_ADDRESS` in your `.env`

## World Wallet

Your world has its own wallet that deposits go into, and withdrawals come out of.

You can generate a new wallet by running `node ./scripts/gen-wallet.js` and pasting these values into your `.env`

## player.wallet

Either a `String` wallet address or `null`. This is automatically synchronized and accessable by apps on both the client and server.

## world.on('wallet', callback)

Apps can also subscribe to global player wallet changes on both the client and server.

```jsx
world.on('wallet', e => {
// e.playerId
// e.wallet
})
```

## player.connect()

On the client this invokes a connect and sign flow, which is then verified on the server before updating the `player.wallet` value and emitting the `wallet` change event above.

On the server this sends a network event to the client to invoke the above.

## player.disconnect()

Disconnects the players current wallet. Can be used on the client or server, and clears the `player.wallet` value. Also emits a `wallet` change event.

## player.deposit(amount)

Server only.

Generates an unsigned transaction for the player to send `amount` to the world wallet, sends it to the client to be signed, and is then confirmed back on the server.

Returns a promise that resolves with the signature, or rejects with an error code.

## player.withdraw(amount)

Server only.

Generates an unsigned transaction for the player to receive `amoutn` from the world wallet, sends it to the client to be signed, and is then signed and confirmed back on the server.

Returns a promise that resolves with the signature, or rejects with an error code.
Loading