---
name: stage-fun-account
description: Create an account and log in to stage.fun on Monad via WalletConnect. Use when a user asks to set up, connect, or log in to stage.fun. Covers WalletConnect pairing via Privy, SIWE signing, cookie persistence, and funding the embedded wallet for gas. Requires an encrypted wallet at ~/.openclaw/wallet/wallet.json and the wc-wallet.js script, and for a new account (while Stage asks for one) the invite password.
---

# Stage.fun Account Setup

Stage.fun (`https://app.stage.fun`) uses Privy for auth. Login is via WalletConnect — your local wallet signs a SIWE message to prove ownership, then Privy creates an embedded wallet that pays gas for all on-chain actions.

## Prerequisites

- Encrypted wallet at `~/.openclaw/wallet/wallet.json`
- `WALLET_PASSWORD` in `~/.openclaw/.env`
- `wc-wallet.js` at `~/.openclaw/wallet/wc-wallet.js`
- OpenClaw browser (profile: `openclaw`)
- For a **new** account, while Stage asks for one: the invite password (from your operator). Existing accounts never need it.

## Wallet Architecture

After login, Privy creates three wallets:

| Wallet | Purpose | Needs MON |
|--------|---------|-----------|
| **Imported** (your wallet.json address) | Auth only — SIWE signing | No |
| **Embedded** (created by Privy) | Pays gas for all transactions | **Yes** |
| **Smart** (created by Privy) | Account abstraction | No |

**Critical:** Fund the **embedded** wallet, not the imported one.

## WC Wallet Script Config

`wc-wallet.js` must include these or login silently fails:

```javascript
const SUPPORTED_CHAINS = ["eip155:10143", "eip155:143", "eip155:1"];
const SUPPORTED_METHODS = [
  "personal_sign", "eth_sign", "eth_signTypedData",
  "eth_signTypedData_v4", "eth_sendTransaction", "eth_signTransaction"
];
```

## Login Flow

### Step 1: Open stage.fun

Open `https://app.stage.fun/pools` in the OpenClaw browser with profile `openclaw`.

### Step 2: Open the login modal

Click the "Log in" button in the top bar (it is there only while signed out). The app uses client-side rendering, so use JS evaluation:

```javascript
document.querySelector('[data-testid="login-button"]').click()
// Fallback by text:
// Array.from(document.querySelectorAll('button')).find(function(b){return b.textContent.trim()==='Log in'}).click()
```

While new accounts need an invite password, a "Log in to Stage" dialog opens first (skip this when Privy's modal opens straight away). An existing account clicks "Log in":

```javascript
document.querySelector('[data-testid="login-existing"]').click()
```

A new account enters the invite password and clicks "Create account" (the pass lasts 30 days; save cookies in Step 7 to keep it):

```javascript
var input = document.querySelector('[data-testid="login-password-input"]');
var setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
setter.call(input, 'THE_INVITE_PASSWORD');
input.dispatchEvent(new Event('input', { bubbles: true }));
document.querySelector('[data-testid="login-password-submit"]').click()
```

A wrong password says so under the field; 10 wrong tries lock the address out for 15 minutes. Privy's modal opens next.

### Step 3: Select WalletConnect

Click "Continue with a wallet":
```javascript
Array.from(document.querySelectorAll('button')).find(function(b){return b.textContent.includes('Continue with a wallet')}).click()
```

Then click "WalletConnect":
```javascript
Array.from(document.querySelectorAll('button')).find(function(b){return b.textContent.trim()==='WalletConnect'}).click()
```

### Step 4: Extract the WC URI

A QR code modal appears. The URI is behind the "Copy link" button. Intercept the clipboard to capture it:

```javascript
// 1. Inject interceptor
(function(){window.__wcUri='';navigator.clipboard.writeText=function(t){window.__wcUri=t;return Promise.resolve()};return 'ok'})()

// 2. Click copy
Array.from(document.querySelectorAll('button')).find(function(b){return b.textContent.includes('Copy link')}).click()

// 3. Read URI
window.__wcUri
// Returns: wc:abc123...@2?expiryTimestamp=...&relay-protocol=irn&symKey=...
```

**WC URIs expire in ~60 seconds.** Extract and use immediately.

### Step 5: Run the wallet script

```bash
source ~/.openclaw/.env && cd ~/.openclaw/wallet && node wc-wallet.js 'WC_URI_HERE'
```

Expected output:
```
Decrypting wallet...
Wallet address: 0x...
📋 Session proposal received from: stagefun
✅ Session approved!
📝 Request: personal_sign
✅ Signed!
```

If `personal_sign` never appears, check SUPPORTED_METHODS in wc-wallet.js.

### Step 6: Verify login

Take a screenshot. The "Log in" button is gone and the top right shows your account avatar (a button labelled "Account", with Portfolio and Sign out in its menu), confirming login:

```javascript
!document.querySelector('[data-testid="login-button"]') && !!document.querySelector('button[aria-label="Account"]')
// true once logged in
```

### Step 7: Save cookies

```bash
openclaw browser --browser-profile openclaw cookies > ~/.openclaw/wallet/stage-fun-cookies.json && chmod 600 ~/.openclaw/wallet/stage-fun-cookies.json
```

## Funding the Embedded Wallet

On-chain actions require MON in the embedded wallet. To send MON from your local wallet:

```javascript
// send-mon.js — save to ~/.openclaw/wallet/send-mon.js
const { ethers } = require('ethers');
const crypto = require('crypto');
const fs = require('fs');

function decryptWallet() {
  var data = JSON.parse(fs.readFileSync('/home/clawdbot/.openclaw/wallet/wallet.json'));
  var salt = Buffer.from(data.salt, 'hex');
  var iv = Buffer.from(data.iv, 'hex');
  var authTag = Buffer.from(data.authTag, 'hex');
  var key = crypto.scryptSync(process.env.WALLET_PASSWORD, salt, 32);
  var decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
  decipher.setAuthTag(authTag);
  var pk = decipher.update(data.encrypted_key, 'hex', 'utf8');
  pk += decipher.final('utf8');
  return new ethers.Wallet(pk);
}

async function main() {
  var provider = new ethers.JsonRpcProvider('https://rpc.monad.xyz');
  var wallet = decryptWallet().connect(provider);
  var tx = await wallet.sendTransaction({
    to: process.argv[2],
    value: ethers.parseEther(process.argv[3])
  });
  console.log('Tx:', tx.hash);
  await tx.wait();
  console.log('Confirmed');
}
main().catch(console.error);
```

Usage:
```bash
source ~/.openclaw/.env && cd ~/.openclaw/wallet && node send-mon.js <EMBEDDED_WALLET_ADDRESS> 2
```

**Use mainnet RPC** (`https://rpc.monad.xyz`), not testnet. Monad mainnet chain ID is **143** (testnet is 10143).

## Troubleshooting

| Problem | Cause | Fix |
|---------|-------|-----|
| "Could not log in with wallet" | `personal_sign` never sent | Add `personal_sign` to SUPPORTED_METHODS in wc-wallet.js |
| "A user cannot have more than one ethereum embedded and one imported wallet" | Account already exists | Ignore — check Privy dashboard, account was likely created |
| Session approved but no signing request | Wrong SUPPORTED_CHAINS | Add `eip155:10143` to SUPPORTED_CHAINS |
| "Insufficient MON balance for gas" | Embedded wallet unfunded | Send MON to the embedded wallet address |
