Juicebox V5 Interaction UI Generator
Generate simple frontends for interacting with existing Juicebox projects using viem and shared styles. Pay into treasuries, cash out tokens, view project state - no build tools required.
Philosophy
Let users interact with Juicebox projects without touching a command line.
These UIs are for:
- Paying into a project treasury
- Cashing out tokens for ETH
- Viewing project configuration and state
- Claiming ERC-20 tokens from credits
Template: Project Payment UI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pay Project</title>
<link rel="stylesheet" href="/shared/styles.css">
<style>
body { max-width: 480px; margin: 0 auto; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 3rem; }
.input-suffix span { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-75%); color: var(--text-muted); }
.receive-preview { background: var(--bg-primary); border-radius: 4px; padding: 0.75rem; margin: 0.75rem 0; text-align: center; }
.receive-amount { font-size: 1.25rem; font-weight: 600; }
.receive-label { font-size: 0.75rem; color: var(--text-muted); }
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
</style>
</head>
<body>
<h1>Pay Project #<span id="project-id">1</span></h1>
<p class="subtitle">Contribute ETH and receive tokens</p>
<div class="card">
<button id="connect-btn" class="btn" Wallet</button>
<div id="wallet-status" class="hidden">
<div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
<div class="stat-row"><span class="stat-label">Balance</span><span class="stat-value" id="wallet-balance"></span></div>
</div>
</div>
<div class="card" id="project-stats">
<div class="stat-row"><span class="stat-label">Treasury Balance</span><span class="stat-value" id="treasury-balance">-</span></div>
<div class="stat-row"><span class="stat-label">Token Supply</span><span class="stat-value" id="token-supply">-</span></div>
<div class="stat-row"><span class="stat-label">Tokens per ETH</span><span class="stat-value" id="tokens-per-eth">-</span></div>
</div>
<div class="card">
<label>Amount to Pay</label>
<div class="input-suffix">
<input type="number" id="pay-amount" placeholder="0.0" step="0.001" min="0"
<span>ETH</span>
</div>
<div class="receive-preview">
<div class="receive-amount" id="receive-amount">0</div>
<div class="receive-label">tokens you'll receive</div>
</div>
<label>Memo (optional)</label>
<input type="text" id="memo" placeholder="Thanks for building!">
<button id="pay-btn" class="btn" disabled>Pay Project</button>
</div>
<div id="tx-status" class="card hidden">
<span id="tx-state"></span>
<a id="tx-link" href="#" target="_blank" class="hidden">View transaction</a>
</div>
<script type="module">
import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther, getContract } from 'https://esm.sh/viem';
import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
// Configuration
const PROJECT_ID = 1n;
const CHAIN_ID = 1;
const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
const TERMINAL_ABI = [
{ name: 'pay', type: 'function', stateMutability: 'payable',
inputs: [
{ name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
{ name: 'minReturnedTokens', type: 'uint256' }, { name: 'memo', type: 'string' },
{ name: 'metadata', type: 'bytes' }
],
outputs: [{ type: 'uint256' }]
}
];
let publicClient, walletClient, address, tokensPerEth = 0n;
document.getElementById('project-id').textContent = PROJECT_ID.toString();
window.connectWallet = async function() {
if (!window.ethereum) { alert('Please install MetaMask'); return; }
const chain = CHAINS[CHAIN_ID];
const rpc = CHAIN_CONFIGS[CHAIN_ID]?.rpc || chain.rpcUrls.default.http[0];
publicClient = createPublicClient({ chain, transport: http(rpc) });
walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
const [addr] = await walletClient.requestAddresses();
address = addr;
const chainId = await walletClient.getChainId();
if (chainId !== CHAIN_ID) {
try { await walletClient.switchChain({ id: CHAIN_ID }); }
catch { alert(`Please switch to the correct network (Chain ID: ${CHAIN_ID})`); return; }
}
document.getElementById('wallet-address').textContent = truncateAddress(address);
const balance = await publicClient.getBalance({ address });
document.getElementById('wallet-balance').textContent = `${parseFloat(formatEther(balance)).toFixed(4)} ETH`;
document.getElementById('wallet-status').classList.remove('hidden');
document.getElementById('connect-btn').classList.add('hidden');
document.getElementById('pay-btn').disabled = false;
await loadProjectStats();
};
async function loadProjectStats() {
tokensPerEth = parseEther('1000000');
document.getElementById('treasury-balance').textContent = '10.5 ETH';
document.getElementById('token-supply').textContent = '10,500,000';
document.getElementById('tokens-per-eth').textContent = '1,000,000';
}
window.updateReceivePreview = function() {
const amount = document.getElementById('pay-amount').value || '0';
if (tokensPerEth > 0n) {
const receive = parseFloat(amount) * parseFloat(formatEther(tokensPerEth));
document.getElementById('receive-amount').textContent = receive.toLocaleString(undefined, { maximumFractionDigits: 0 });
}
};
window.pay = async function() {
const amount = document.getElementById('pay-amount').value;
const memo = document.getElementById('memo').value || '';
if (!amount || parseFloat(amount) <= 0) { alert('Enter an amount to pay'); return; }
const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
const value = parseEther(amount);
showTxPending('Please confirm in wallet...');
try {
const hash = await walletClient.writeContract({
address: terminal,
abi: TERMINAL_ABI,
functionName: 'pay',
args: [PROJECT_ID, NATIVE_TOKEN, value, address, 0n, memo, '0x'],
value,
account: address
});
showTxSent(hash);
await publicClient.waitForTransactionReceipt({ hash });
showTxConfirmed();
} catch (error) {
showTxError(error);
}
};
function showTxPending(msg) {
document.getElementById('tx-status').classList.remove('hidden');
document.getElementById('tx-state').textContent = msg;
document.getElementById('tx-link').classList.add('hidden');
}
function showTxSent(hash) {
document.getElementById('tx-state').textContent = 'Transaction sent...';
const link = document.getElementById('tx-link');
link.href = getTxUrl(CHAIN_ID, hash);
link.classList.remove('hidden');
}
function showTxConfirmed() { document.getElementById('tx-state').textContent = 'Payment successful!'; }
function showTxError(error) { document.getElementById('tx-state').textContent = error.shortMessage || error.message; }
</script>
</body>
</html>
Template: Cash Out UI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cash Out Tokens</title>
<link rel="stylesheet" href="/shared/styles.css">
<style>
body { max-width: 480px; margin: 0 auto; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 4rem; }
.input-suffix span { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-75%); color: var(--text-muted); }
.receive-preview { background: var(--bg-primary); border-radius: 4px; padding: 0.75rem; margin: 0.75rem 0; text-align: center; }
.receive-amount { font-size: 1.25rem; font-weight: 600; }
.receive-label { font-size: 0.75rem; color: var(--text-muted); }
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.warning { border-color: var(--error) !important; }
.warning p { font-size: 0.875rem; color: var(--text-muted); }
</style>
</head>
<body>
<h1>Cash Out</h1>
<p class="subtitle">Burn tokens to reclaim ETH from treasury</p>
<div class="card">
<button id="connect-btn" class="btn" Wallet</button>
<div id="wallet-status" class="hidden">
<div class="stat-row"><span class="stat-label">Your Token Balance</span><span class="stat-value" id="token-balance">-</span></div>
</div>
</div>
<div class="card">
<label>Tokens to Cash Out</label>
<div class="input-suffix">
<input type="number" id="cash-out-amount" placeholder="0"
<span>tokens</span>
</div>
<button class="btn btn-secondary" style="margin-bottom: 0.75rem;">Max</button>
<div class="receive-preview">
<div class="receive-amount" id="reclaim-amount">0</div>
<div class="receive-label">ETH you'll receive</div>
</div>
<button id="cashout-btn" class="btn" disabled>Cash Out</button>
</div>
<div class="card warning">
<p>Cash outs burn your tokens permanently. You'll receive your proportional share of the treasury surplus.</p>
</div>
<div id="tx-status" class="card hidden"></div>
<script type="module">
import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther } from 'https://esm.sh/viem';
import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
const PROJECT_ID = 1n;
const CHAIN_ID = 1;
const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
const TERMINAL_ABI = [
{ name: 'cashOutTokensOf', type: 'function', stateMutability: 'nonpayable',
inputs: [
{ name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' },
{ name: 'cashOutCount', type: 'uint256' }, { name: 'tokenToReclaim', type: 'address' },
{ name: 'minTokensReclaimed', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
{ name: 'metadata', type: 'bytes' }
],
outputs: [{ type: 'uint256' }]
}
];
let publicClient, walletClient, address, tokenBalance = 0n;
window.connectWallet = async function() {
if (!window.ethereum) { alert('Please install MetaMask'); return; }
const chain = CHAINS[CHAIN_ID];
publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
const [addr] = await walletClient.requestAddresses();
address = addr;
document.getElementById('wallet-status').classList.remove('hidden');
document.getElementById('connect-btn').classList.add('hidden');
await loadTokenBalance();
};
async function loadTokenBalance() {
tokenBalance = parseEther('1000000');
document.getElementById('token-balance').textContent = parseInt(formatEther(tokenBalance)).toLocaleString() + ' tokens';
document.getElementById('cashout-btn').disabled = false;
}
window.setMax = function() {
document.getElementById('cash-out-amount').value = parseInt(formatEther(tokenBalance));
updateCashOutPreview();
};
window.updateCashOutPreview = function() {
const amount = document.getElementById('cash-out-amount').value || '0';
const reclaim = parseFloat(amount) * 0.00001;
document.getElementById('reclaim-amount').textContent = reclaim.toFixed(4) + ' ETH';
};
window.cashOut = async function() {
const amount = document.getElementById('cash-out-amount').value;
const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
document.getElementById('tx-status').classList.remove('hidden');
document.getElementById('tx-status').textContent = 'Please confirm in wallet...';
try {
const hash = await walletClient.writeContract({
address: terminal,
abi: TERMINAL_ABI,
functionName: 'cashOutTokensOf',
args: [address, PROJECT_ID, parseEther(amount), NATIVE_TOKEN, 0n, address, '0x'],
account: address
});
document.getElementById('tx-status').innerHTML = `Transaction sent... <a href="${getTxUrl(CHAIN_ID, hash)}" target="_blank">View</a>`;
await publicClient.waitForTransactionReceipt({ hash });
document.getElementById('tx-status').textContent = 'Cash out successful!';
} catch (error) {
document.getElementById('tx-status').textContent = error.shortMessage || error.message;
}
};
</script>
</body>
</html>
Template: NFT Mint UI (721 Hook)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mint NFT</title>
<link rel="stylesheet" href="/shared/styles.css">
<style>
body { max-width: 640px; margin: 0 auto; }
.tiers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tier-card { cursor: pointer; transition: border-color 0.2s; }
.tier-card:hover, .tier-card.selected { border-color: var(--jb-yellow); }
.tier-price { font-size: 1.25rem; font-weight: 600; color: var(--jb-yellow); }
.tier-remaining { font-size: 0.875rem; color: var(--text-muted); }
</style>
</head>
<body>
<h1>Mint NFT</h1>
<div class="card">
<button id="connect-btn" class="btn" Wallet</button>
<div id="wallet-status" class="hidden">
<div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
</div>
</div>
<div id="tiers-container" class="tiers-grid"></div>
<div class="card hidden" id="selected-tier">
<h3 id="tier-name"></h3>
<div class="stat-row"><span class="stat-label">Price</span><span class="stat-value tier-price" id="tier-price"></span></div>
<div class="stat-row"><span class="stat-label">Remaining</span><span class="stat-value" id="tier-remaining"></span></div>
<button class="btn" for <span id="mint-price"></span> ETH</button>
</div>
<div id="tx-status" class="card hidden"></div>
<script type="module">
import { createPublicClient, createWalletClient, http, custom, parseEther, encodeAbiParameters } from 'https://esm.sh/viem';
import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
const PROJECT_ID = 1n;
const CHAIN_ID = 1;
const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
const TERMINAL_ABI = [
{ name: 'pay', type: 'function', stateMutability: 'payable',
inputs: [
{ name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
{ name: 'minReturnedTokens', type: 'uint256' }, { name: 'memo', type: 'string' },
{ name: 'metadata', type: 'bytes' }
],
outputs: [{ type: 'uint256' }]
}
];
const TIERS = [
{ id: 1, name: 'Common', price: '0.01', remaining: 100 },
{ id: 2, name: 'Rare', price: '0.1', remaining: 50 },
{ id: 3, name: 'Legendary', price: '1.0', remaining: 10 }
];
let publicClient, walletClient, address, selectedTier = null;
function renderTiers() {
document.getElementById('tiers-container').innerHTML = TIERS.map(tier => `
<div class="card tier-card" data-id="${tier.id}"
<h3>${tier.name}</h3>
<div class="tier-price">${tier.price} ETH</div>
<div class="tier-remaining">${tier.remaining} left</div>
</div>
`).join('');
}
window.selectTier = function(tierId) {
document.querySelectorAll('.tier-card').forEach(c => c.classList.remove('selected'));
document.querySelector(`[data-id="${tierId}"]`).classList.add('selected');
selectedTier = TIERS.find(t => t.id === tierId);
document.getElementById('tier-name').textContent = selectedTier.name;
document.getElementById('tier-price').textContent = selectedTier.price + ' ETH';
document.getElementById('tier-remaining').textContent = selectedTier.remaining;
document.getElementById('mint-price').textContent = selectedTier.price;
document.getElementById('selected-tier').classList.remove('hidden');
};
window.connectWallet = async function() {
if (!window.ethereum) { alert('Please install MetaMask'); return; }
const chain = CHAINS[CHAIN_ID];
publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
const [addr] = await walletClient.requestAddresses();
address = addr;
document.getElementById('wallet-address').textContent = truncateAddress(address);
document.getElementById('wallet-status').classList.remove('hidden');
document.getElementById('connect-btn').classList.add('hidden');
};
window.mint = async function() {
if (!selectedTier || !address) return;
const metadata = encodeAbiParameters(
[{ type: 'bytes4' }, { type: 'bool' }, { type: 'uint16[]' }],
['0x00000000', true, [selectedTier.id]]
);
const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
const value = parseEther(selectedTier.price);
document.getElementById('tx-status').classList.remove('hidden');
document.getElementById('tx-status').textContent = 'Please confirm in wallet...';
try {
const hash = await walletClient.writeContract({
address: terminal,
abi: TERMINAL_ABI,
functionName: 'pay',
args: [PROJECT_ID, NATIVE_TOKEN, value, address, 0n, '', metadata],
value,
account: address
});
document.getElementById('tx-status').innerHTML = `Transaction sent... <a href="${getTxUrl(CHAIN_ID, hash)}" target="_blank">View</a>`;
await publicClient.waitForTransactionReceipt({ hash });
document.getElementById('tx-status').textContent = 'NFT minted!';
} catch (error) {
document.getElementById('tx-status').textContent = error.shortMessage || error.message;
}
};
renderTiers();
</script>
</body>
</html>
Template: Project Admin UI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project Admin</title>
<link rel="stylesheet" href="/shared/styles.css">
<style>
body { max-width: 640px; margin: 0 auto; }
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
h2 { font-size: 1rem; color: var(--text-muted); margin: 1rem 0 0.75rem; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.splits-preview { background: var(--bg-primary); padding: 0.75rem; border-radius: 4px; margin-bottom: 1rem; font-size: 0.875rem; }
</style>
</head>
<body>
<h1>Project #<span id="project-id">1</span> Admin</h1>
<p class="subtitle">Manage treasury operations</p>
<div class="card">
<button id="connect-btn" class="btn" Wallet</button>
<div id="wallet-status" class="hidden">
<div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
<div class="stat-row"><span class="stat-label">Owner Status</span><span class="stat-value" id="owner-status">Checking...</span></div>
</div>
</div>
<div class="card" id="treasury-card">
<h2>Treasury Status</h2>
<div class="stat-row"><span class="stat-label">Balance</span><span class="stat-value" id="treasury-balance">-</span></div>
<div class="stat-row"><span class="stat-label">Distributable</span><span class="stat-value" id="distributable">-</span></div>
<div class="stat-row"><span class="stat-label">Payout Limit</span><span class="stat-value" id="payout-limit">-</span></div>
<div class="stat-row"><span class="stat-label">Current Cycle</span><span class="stat-value" id="current-cycle">-</span></div>
</div>
<div class="tabs">
<div class="tab active" Payouts</div>
<div class="tab" Allowance</div>
<div class="tab"
</div>
<div id="payouts-tab" class="tab-content active">
<div class="card">
<h2>Distribute to Splits</h2>
<p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem;">Send funds to configured split recipients.</p>
<label>Amount to Distribute (ETH)</label>
<input type="number" id="payout-amount" placeholder="0.0" step="0.01">
<button class="btn btn-secondary" style="margin-bottom: 1rem;">Max Available</button>
<div class="splits-preview">
<strong>Split Recipients:</strong>
<div id="splits-list" style="margin-top: 0.5rem; color: var(--text-muted);">Loading...</div>
</div>
<button class="btn" Payouts</button>
</div>
</div>
<div id="allowance-tab" class="tab-content">
<div class="card">
<h2>Use Surplus Allowance</h2>
<p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem;">Withdraw from surplus (discretionary spending).</p>
<div class="stat-row"><span class="stat-label">Remaining Allowance</span><span class="stat-value" id="surplus-allowance">-</span></div>
<label>Amount to Withdraw (ETH)</label>
<input type="number" id="allowance-amount" placeholder="0.0" step="0.01">
<label>Beneficiary Address</label>
<input type="text" id="allowance-beneficiary" placeholder="0x... (defaults to connected wallet)">
<button class="btn" from Surplus</button>
</div>
</div>
<div id="reserved-tab" class="tab-content">
<div class="card">
<h2>Distribute Reserved Tokens</h2>
<p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem;">Mint and distribute accumulated reserved tokens.</p>
<div class="stat-row"><span class="stat-label">Pending Reserved Tokens</span><span class="stat-value" id="pending-reserved">-</span></div>
<button class="btn" Reserved Tokens</button>
</div>
</div>
<div id="tx-status" class="card hidden">
<span id="tx-state"></span>
<a id="tx-link" href="#" target="_blank" class="hidden">View transaction</a>
</div>
<script type="module">
import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther } from 'https://esm.sh/viem';
import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
const PROJECT_ID = 1n;
const CHAIN_ID = 1;
const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
const TERMINAL_ABI = [
{ name: 'sendPayoutsOf', type: 'function', stateMutability: 'nonpayable',
inputs: [
{ name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' }, { name: 'currency', type: 'uint256' },
{ name: 'minTokensPaidOut', type: 'uint256' }
],
outputs: [{ type: 'uint256' }]
},
{ name: 'useAllowanceOf', type: 'function', stateMutability: 'nonpayable',
inputs: [
{ name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' }, { name: 'currency', type: 'uint256' },
{ name: 'minTokensPaidOut', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
{ name: 'feeBeneficiary', type: 'address' }, { name: 'memo', type: 'string' }
],
outputs: [{ type: 'uint256' }]
}
];
const CONTROLLER_ABI = [
{ name: 'sendReservedTokensToSplitsOf', type: 'function', stateMutability: 'nonpayable',
inputs: [{ name: 'projectId', type: 'uint256' }],
outputs: [{ type: 'uint256' }]
}
];
const PROJECTS_ABI = [
{ name: 'ownerOf', type: 'function', stateMutability: 'view',
inputs: [{ name: 'tokenId', type: 'uint256' }],
outputs: [{ type: 'address' }]
}
];
let publicClient, walletClient, address;
document.getElementById('project-id').textContent = PROJECT_ID.toString();
window.showTab = function(tabName) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
event.target.classList.add('active');
document.getElementById(`${tabName}-tab`).classList.add('active');
};
window.connectWallet = async function() {
if (!window.ethereum) { alert('Please install MetaMask'); return; }
const chain = CHAINS[CHAIN_ID];
publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
const [addr] = await walletClient.requestAddresses();
address = addr;
document.getElementById('wallet-address').textContent = truncateAddress(address);
document.getElementById('wallet-status').classList.remove('hidden');
document.getElementById('connect-btn').classList.add('hidden');
const projects = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBProjects;
const owner = await publicClient.readContract({ address: projects, abi: PROJECTS_ABI, functionName: 'ownerOf', args: [PROJECT_ID] });
const isOwner = owner.toLowerCase() === address.toLowerCase();
document.getElementById('owner-status').textContent = isOwner ? 'Owner' : 'Not Owner';
await loadTreasuryStats();
};
async function loadTreasuryStats() {
document.getElementById('treasury-balance').textContent = '10.5 ETH';
document.getElementById('distributable').textContent = '8.0 ETH';
document.getElementById('payout-limit').textContent = '8.0 ETH / cycle';
document.getElementById('current-cycle').textContent = '3';
document.getElementById('surplus-allowance').textContent = '2.5 ETH';
document.getElementById('pending-reserved').textContent = '50,000 tokens';
document.getElementById('splits-list').innerHTML = '0x1234...5678 (50%), Project #2 (50%)';
}
window.setMaxPayout = () => document.getElementById('payout-amount').value = '8.0';
window.sendPayouts = async function() {
const amount = document.getElementById('payout-amount').value;
if (!amount || parseFloat(amount) <= 0) { alert('Enter an amount'); return; }
const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
showTxPending('Please confirm in wallet...');
try {
const hash = await walletClient.writeContract({
address: terminal,
abi: TERMINAL_ABI,
functionName: 'sendPayoutsOf',
args: [PROJECT_ID, NATIVE_TOKEN, parseEther(amount), 0n, 0n],
account: address
});
showTxSent(hash);
await publicClient.waitForTransactionReceipt({ hash });
showTxConfirmed();
await loadTreasuryStats();
} catch (error) { showTxError(error); }
};
window.useAllowance = async function() {
const amount = document.getElementById('allowance-amount').value;
const beneficiary = document.getElementById('allowance-beneficiary').value || address;
if (!amount || parseFloat(amount) <= 0) { alert('Enter an amount'); return; }
const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
showTxPending('Please confirm in wallet...');
try {
const hash = await walletClient.writeContract({
address: terminal,
abi: TERMINAL_ABI,
functionName: 'useAllowanceOf',
args: [PROJECT_ID, NATIVE_TOKEN, parseEther(amount), 0n, 0n, beneficiary, address, 'Surplus allowance withdrawal'],
account: address
});
showTxSent(hash);
await publicClient.waitForTransactionReceipt({ hash });
showTxConfirmed();
await loadTreasuryStats();
} catch (error) { showTxError(error); }
};
window.sendReservedTokens = async function() {
const controller = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBController;
showTxPending('Please confirm in wallet...');
try {
const hash = await walletClient.writeContract({
address: controller,
abi: CONTROLLER_ABI,
functionName: 'sendReservedTokensToSplitsOf',
args: [PROJECT_ID],
account: address
});
showTxSent(hash);
await publicClient.waitForTransactionReceipt({ hash });
showTxConfirmed();
await loadTreasuryStats();
} catch (error) { showTxError(error); }
};
function showTxPending(msg) {
document.getElementById('tx-status').classList.remove('hidden');
document.getElementById('tx-state').textContent = msg;
document.getElementById('tx-link').classList.add('hidden');
}
function showTxSent(hash) {
document.getElementById('tx-state').textContent = 'Transaction sent...';
const link = document.getElementById('tx-link');
link.href = getTxUrl(CHAIN_ID, hash);
link.classList.remove('hidden');
}
function showTxConfirmed() { document.getElementById('tx-state').textContent = 'Transaction confirmed!'; }
function showTxError(error) { document.getElementById('tx-state').textContent = error.shortMessage || error.message; }
</script>
</body>
</html>
Template: Claim Tokens UI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Claim Tokens</title>
<link rel="stylesheet" href="/shared/styles.css">
<style>
body { max-width: 480px; margin: 0 auto; }
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
h2 { font-size: 1rem; color: var(--text-muted); margin-bottom: 1rem; }
.info { background: var(--bg-primary); padding: 0.75rem; border-radius: 4px; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
.warning-card { border-color: var(--accent) !important; }
.warning-card p { font-size: 0.875rem; }
</style>
</head>
<body>
<h1>Claim Tokens</h1>
<p class="subtitle">Convert credits to ERC-20 tokens</p>
<div class="card">
<button id="connect-btn" class="btn" Wallet</button>
<div id="wallet-status" class="hidden">
<div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
</div>
</div>
<div class="card">
<h2>Your Balances</h2>
<div class="stat-row"><span class="stat-label">Credits (unclaimed)</span><span class="stat-value" id="credit-balance">-</span></div>
<div class="stat-row"><span class="stat-label">ERC-20 Tokens</span><span class="stat-value" id="token-balance">-</span></div>
<div class="stat-row"><span class="stat-label">Total Balance</span><span class="stat-value" id="total-balance">-</span></div>
</div>
<div class="card" id="claim-section">
<div class="info">Credits are stored in the Juicebox protocol. Claiming converts them to ERC-20 tokens in your wallet.</div>
<label>Amount to Claim</label>
<input type="number" id="claim-amount" placeholder="0">
<button class="btn btn-secondary" All</button>
<button id="claim-btn" class="btn" disabled>Claim Tokens</button>
</div>
<div class="card warning-card hidden" id="no-token-warning">
<p>This project hasn't deployed an ERC-20 token yet. Credits cannot be claimed until the project owner deploys one.</p>
</div>
<div id="tx-status" class="card hidden">
<span id="tx-state"></span>
<a id="tx-link" href="#" target="_blank" class="hidden">View transaction</a>
</div>
<script type="module">
import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther, zeroAddress } from 'https://esm.sh/viem';
import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
const PROJECT_ID = 1n;
const CHAIN_ID = 1;
const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
const CONTROLLER_ABI = [
{ name: 'claimTokensFor', type: 'function', stateMutability: 'nonpayable',
inputs: [
{ name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' },
{ name: 'tokenCount', type: 'uint256' }, { name: 'beneficiary', type: 'address' }
],
outputs: []
}
];
const TOKENS_ABI = [
{ name: 'creditBalanceOf', type: 'function', stateMutability: 'view',
inputs: [{ name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' }],
outputs: [{ type: 'uint256' }]
},
{ name: 'tokenOf', type: 'function', stateMutability: 'view',
inputs: [{ name: 'projectId', type: 'uint256' }],
outputs: [{ type: 'address' }]
},
{ name: 'totalBalanceOf', type: 'function', stateMutability: 'view',
inputs: [{ name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' }],
outputs: [{ type: 'uint256' }]
}
];
let publicClient, walletClient, address, creditBalance = 0n;
window.connectWallet = async function() {
if (!window.ethereum) { alert('Please install MetaMask'); return; }
const chain = CHAINS[CHAIN_ID];
publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
const [addr] = await walletClient.requestAddresses();
address = addr;
document.getElementById('wallet-address').textContent = truncateAddress(address);
document.getElementById('wallet-status').classList.remove('hidden');
document.getElementById('connect-btn').classList.add('hidden');
await loadBalances();
};
async function loadBalances() {
const tokens = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBTokens;
const tokenAddr = await publicClient.readContract({ address: tokens, abi: TOKENS_ABI, functionName: 'tokenOf', args: [PROJECT_ID] });
const hasToken = tokenAddr !== zeroAddress;
if (!hasToken) {
document.getElementById('claim-section').classList.add('hidden');
document.getElementById('no-token-warning').classList.remove('hidden');
}
creditBalance = await publicClient.readContract({ address: tokens, abi: TOKENS_ABI, functionName: 'creditBalanceOf', args: [address, PROJECT_ID] });
const totalBalance = await publicClient.readContract({ address: tokens, abi: TOKENS_ABI, functionName: 'totalBalanceOf', args: [address, PROJECT_ID] });
const tokenBalance = totalBalance - creditBalance;
document.getElementById('credit-balance').textContent = parseInt(formatEther(creditBalance)).toLocaleString();
document.getElementById('token-balance').textContent = parseInt(formatEther(tokenBalance)).toLocaleString();
document.getElementById('total-balance').textContent = parseInt(formatEther(totalBalance)).toLocaleString();
if (hasToken && creditBalance > 0n) document.getElementById('claim-btn').disabled = false;
}
window.setMaxClaim = () => document.getElementById('claim-amount').value = parseInt(formatEther(creditBalance));
window.claimTokens = async function() {
const amount = document.getElementById('claim-amount').value;
if (!amount || parseInt(amount) <= 0) { alert('Enter an amount'); return; }
const controller = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBController;
showTxPending('Please confirm in wallet...');
try {
const hash = await walletClient.writeContract({
address: controller,
abi: CONTROLLER_ABI,
functionName: 'claimTokensFor',
args: [address, PROJECT_ID, parseEther(amount), address],
account: address
});
showTxSent(hash);
await publicClient.waitForTransactionReceipt({ hash });
showTxConfirmed();
await loadBalances();
} catch (error) { showTxError(error); }
};
function showTxPending(msg) {
document.getElementById('tx-status').classList.remove('hidden');
document.getElementById('tx-state').textContent = msg;
document.getElementById('tx-link').classList.add('hidden');
}
function showTxSent(hash) {
document.getElementById('tx-state').textContent = 'Transaction sent...';
const link = document.getElementById('tx-link');
link.href = getTxUrl(CHAIN_ID, hash);
link.classList.remove('hidden');
}
function showTxConfirmed() { document.getElementById('tx-state').textContent = 'Tokens claimed!'; }
function showTxError(error) { document.getElementById('tx-state').textContent = error.shortMessage || error.message; }
</script>
</body>
</html>
Template: Project Dashboard UI
…(truncated)
1---
2name: jb-interact-ui
3description: Generate minimal frontends for interacting with existing Juicebox V5 projects. Pay, cash out, claim tokens, view project state - all in standalone HTML files.
4metadata:
5 source: https://skillmd.com/skills/modbender/jb-interact-ui
6---
7
8# Juicebox V5 Interaction UI Generator
9
10Generate simple frontends for interacting with existing Juicebox projects using viem and shared styles. Pay into treasuries, cash out tokens, view project state - no build tools required.
11
12## Philosophy
13
14> **Let users interact with Juicebox projects without touching a command line.**
15
16These UIs are for:
17- Paying into a project treasury
18- Cashing out tokens for ETH
19- Viewing project configuration and state
20- Claiming ERC-20 tokens from credits
21
22## Template: Project Payment UI
23
24```html
25<!DOCTYPE html>
26<html lang="en">
27<head>
28 <meta charset="UTF-8">
29 <meta name="viewport" content="width=device-width, initial-scale=1.0">
30 <title>Pay Project</title>
31 <link rel="stylesheet" href="/shared/styles.css">
32 <style>
33 body { max-width: 480px; margin: 0 auto; }
34 .input-suffix { position: relative; }
35 .input-suffix input { padding-right: 3rem; }
36 .input-suffix span { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-75%); color: var(--text-muted); }
37 .receive-preview { background: var(--bg-primary); border-radius: 4px; padding: 0.75rem; margin: 0.75rem 0; text-align: center; }
38 .receive-amount { font-size: 1.25rem; font-weight: 600; }
39 .receive-label { font-size: 0.75rem; color: var(--text-muted); }
40 .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
41 </style>
42</head>
43<body>
44 <h1>Pay Project #<span id="project-id">1</span></h1>
45 <p class="subtitle">Contribute ETH and receive tokens</p>
46
47 <div class="card">
48 <button id="connect-btn" class="btn" onclick="connectWallet()">Connect Wallet</button>
49 <div id="wallet-status" class="hidden">
50 <div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
51 <div class="stat-row"><span class="stat-label">Balance</span><span class="stat-value" id="wallet-balance"></span></div>
52 </div>
53 </div>
54
55 <div class="card" id="project-stats">
56 <div class="stat-row"><span class="stat-label">Treasury Balance</span><span class="stat-value" id="treasury-balance">-</span></div>
57 <div class="stat-row"><span class="stat-label">Token Supply</span><span class="stat-value" id="token-supply">-</span></div>
58 <div class="stat-row"><span class="stat-label">Tokens per ETH</span><span class="stat-value" id="tokens-per-eth">-</span></div>
59 </div>
60
61 <div class="card">
62 <label>Amount to Pay</label>
63 <div class="input-suffix">
64 <input type="number" id="pay-amount" placeholder="0.0" step="0.001" min="0" oninput="updateReceivePreview()">
65 <span>ETH</span>
66 </div>
67 <div class="receive-preview">
68 <div class="receive-amount" id="receive-amount">0</div>
69 <div class="receive-label">tokens you'll receive</div>
70 </div>
71 <label>Memo (optional)</label>
72 <input type="text" id="memo" placeholder="Thanks for building!">
73 <button id="pay-btn" class="btn" onclick="pay()" disabled>Pay Project</button>
74 </div>
75
76 <div id="tx-status" class="card hidden">
77 <span id="tx-state"></span>
78 <a id="tx-link" href="#" target="_blank" class="hidden">View transaction</a>
79 </div>
80
81 <script type="module">
82 import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther, getContract } from 'https://esm.sh/viem';
83 import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
84 import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
85
86 // Configuration
87 const PROJECT_ID = 1n;
88 const CHAIN_ID = 1;
89
90 const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
91 const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
92
93 const TERMINAL_ABI = [
94 { name: 'pay', type: 'function', stateMutability: 'payable',
95 inputs: [
96 { name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
97 { name: 'amount', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
98 { name: 'minReturnedTokens', type: 'uint256' }, { name: 'memo', type: 'string' },
99 { name: 'metadata', type: 'bytes' }
100 ],
101 outputs: [{ type: 'uint256' }]
102 }
103 ];
104
105 let publicClient, walletClient, address, tokensPerEth = 0n;
106
107 document.getElementById('project-id').textContent = PROJECT_ID.toString();
108
109 window.connectWallet = async function() {
110 if (!window.ethereum) { alert('Please install MetaMask'); return; }
111
112 const chain = CHAINS[CHAIN_ID];
113 const rpc = CHAIN_CONFIGS[CHAIN_ID]?.rpc || chain.rpcUrls.default.http[0];
114
115 publicClient = createPublicClient({ chain, transport: http(rpc) });
116 walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
117
118 const [addr] = await walletClient.requestAddresses();
119 address = addr;
120
121 const chainId = await walletClient.getChainId();
122 if (chainId !== CHAIN_ID) {
123 try { await walletClient.switchChain({ id: CHAIN_ID }); }
124 catch { alert(`Please switch to the correct network (Chain ID: ${CHAIN_ID})`); return; }
125 }
126
127 document.getElementById('wallet-address').textContent = truncateAddress(address);
128 const balance = await publicClient.getBalance({ address });
129 document.getElementById('wallet-balance').textContent = `${parseFloat(formatEther(balance)).toFixed(4)} ETH`;
130 document.getElementById('wallet-status').classList.remove('hidden');
131 document.getElementById('connect-btn').classList.add('hidden');
132 document.getElementById('pay-btn').disabled = false;
133
134 await loadProjectStats();
135 };
136
137 async function loadProjectStats() {
138 tokensPerEth = parseEther('1000000');
139 document.getElementById('treasury-balance').textContent = '10.5 ETH';
140 document.getElementById('token-supply').textContent = '10,500,000';
141 document.getElementById('tokens-per-eth').textContent = '1,000,000';
142 }
143
144 window.updateReceivePreview = function() {
145 const amount = document.getElementById('pay-amount').value || '0';
146 if (tokensPerEth > 0n) {
147 const receive = parseFloat(amount) * parseFloat(formatEther(tokensPerEth));
148 document.getElementById('receive-amount').textContent = receive.toLocaleString(undefined, { maximumFractionDigits: 0 });
149 }
150 };
151
152 window.pay = async function() {
153 const amount = document.getElementById('pay-amount').value;
154 const memo = document.getElementById('memo').value || '';
155 if (!amount || parseFloat(amount) <= 0) { alert('Enter an amount to pay'); return; }
156
157 const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
158 const value = parseEther(amount);
159
160 showTxPending('Please confirm in wallet...');
161
162 try {
163 const hash = await walletClient.writeContract({
164 address: terminal,
165 abi: TERMINAL_ABI,
166 functionName: 'pay',
167 args: [PROJECT_ID, NATIVE_TOKEN, value, address, 0n, memo, '0x'],
168 value,
169 account: address
170 });
171
172 showTxSent(hash);
173 await publicClient.waitForTransactionReceipt({ hash });
174 showTxConfirmed();
175 } catch (error) {
176 showTxError(error);
177 }
178 };
179
180 function showTxPending(msg) {
181 document.getElementById('tx-status').classList.remove('hidden');
182 document.getElementById('tx-state').textContent = msg;
183 document.getElementById('tx-link').classList.add('hidden');
184 }
185 function showTxSent(hash) {
186 document.getElementById('tx-state').textContent = 'Transaction sent...';
187 const link = document.getElementById('tx-link');
188 link.href = getTxUrl(CHAIN_ID, hash);
189 link.classList.remove('hidden');
190 }
191 function showTxConfirmed() { document.getElementById('tx-state').textContent = 'Payment successful!'; }
192 function showTxError(error) { document.getElementById('tx-state').textContent = error.shortMessage || error.message; }
193 </script>
194</body>
195</html>
196```
197
198## Template: Cash Out UI
199
200```html
201<!DOCTYPE html>
202<html lang="en">
203<head>
204 <meta charset="UTF-8">
205 <meta name="viewport" content="width=device-width, initial-scale=1.0">
206 <title>Cash Out Tokens</title>
207 <link rel="stylesheet" href="/shared/styles.css">
208 <style>
209 body { max-width: 480px; margin: 0 auto; }
210 .input-suffix { position: relative; }
211 .input-suffix input { padding-right: 4rem; }
212 .input-suffix span { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-75%); color: var(--text-muted); }
213 .receive-preview { background: var(--bg-primary); border-radius: 4px; padding: 0.75rem; margin: 0.75rem 0; text-align: center; }
214 .receive-amount { font-size: 1.25rem; font-weight: 600; }
215 .receive-label { font-size: 0.75rem; color: var(--text-muted); }
216 .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
217 .warning { border-color: var(--error) !important; }
218 .warning p { font-size: 0.875rem; color: var(--text-muted); }
219 </style>
220</head>
221<body>
222 <h1>Cash Out</h1>
223 <p class="subtitle">Burn tokens to reclaim ETH from treasury</p>
224
225 <div class="card">
226 <button id="connect-btn" class="btn" onclick="connectWallet()">Connect Wallet</button>
227 <div id="wallet-status" class="hidden">
228 <div class="stat-row"><span class="stat-label">Your Token Balance</span><span class="stat-value" id="token-balance">-</span></div>
229 </div>
230 </div>
231
232 <div class="card">
233 <label>Tokens to Cash Out</label>
234 <div class="input-suffix">
235 <input type="number" id="cash-out-amount" placeholder="0" oninput="updateCashOutPreview()">
236 <span>tokens</span>
237 </div>
238 <button class="btn btn-secondary" onclick="setMax()" style="margin-bottom: 0.75rem;">Max</button>
239 <div class="receive-preview">
240 <div class="receive-amount" id="reclaim-amount">0</div>
241 <div class="receive-label">ETH you'll receive</div>
242 </div>
243 <button id="cashout-btn" class="btn" onclick="cashOut()" disabled>Cash Out</button>
244 </div>
245
246 <div class="card warning">
247 <p>Cash outs burn your tokens permanently. You'll receive your proportional share of the treasury surplus.</p>
248 </div>
249
250 <div id="tx-status" class="card hidden"></div>
251
252 <script type="module">
253 import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther } from 'https://esm.sh/viem';
254 import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
255 import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
256
257 const PROJECT_ID = 1n;
258 const CHAIN_ID = 1;
259 const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
260 const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
261
262 const TERMINAL_ABI = [
263 { name: 'cashOutTokensOf', type: 'function', stateMutability: 'nonpayable',
264 inputs: [
265 { name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' },
266 { name: 'cashOutCount', type: 'uint256' }, { name: 'tokenToReclaim', type: 'address' },
267 { name: 'minTokensReclaimed', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
268 { name: 'metadata', type: 'bytes' }
269 ],
270 outputs: [{ type: 'uint256' }]
271 }
272 ];
273
274 let publicClient, walletClient, address, tokenBalance = 0n;
275
276 window.connectWallet = async function() {
277 if (!window.ethereum) { alert('Please install MetaMask'); return; }
278
279 const chain = CHAINS[CHAIN_ID];
280 publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
281 walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
282
283 const [addr] = await walletClient.requestAddresses();
284 address = addr;
285
286 document.getElementById('wallet-status').classList.remove('hidden');
287 document.getElementById('connect-btn').classList.add('hidden');
288 await loadTokenBalance();
289 };
290
291 async function loadTokenBalance() {
292 tokenBalance = parseEther('1000000');
293 document.getElementById('token-balance').textContent = parseInt(formatEther(tokenBalance)).toLocaleString() + ' tokens';
294 document.getElementById('cashout-btn').disabled = false;
295 }
296
297 window.setMax = function() {
298 document.getElementById('cash-out-amount').value = parseInt(formatEther(tokenBalance));
299 updateCashOutPreview();
300 };
301
302 window.updateCashOutPreview = function() {
303 const amount = document.getElementById('cash-out-amount').value || '0';
304 const reclaim = parseFloat(amount) * 0.00001;
305 document.getElementById('reclaim-amount').textContent = reclaim.toFixed(4) + ' ETH';
306 };
307
308 window.cashOut = async function() {
309 const amount = document.getElementById('cash-out-amount').value;
310 const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
311
312 document.getElementById('tx-status').classList.remove('hidden');
313 document.getElementById('tx-status').textContent = 'Please confirm in wallet...';
314
315 try {
316 const hash = await walletClient.writeContract({
317 address: terminal,
318 abi: TERMINAL_ABI,
319 functionName: 'cashOutTokensOf',
320 args: [address, PROJECT_ID, parseEther(amount), NATIVE_TOKEN, 0n, address, '0x'],
321 account: address
322 });
323
324 document.getElementById('tx-status').innerHTML = `Transaction sent... <a href="${getTxUrl(CHAIN_ID, hash)}" target="_blank">View</a>`;
325 await publicClient.waitForTransactionReceipt({ hash });
326 document.getElementById('tx-status').textContent = 'Cash out successful!';
327 } catch (error) {
328 document.getElementById('tx-status').textContent = error.shortMessage || error.message;
329 }
330 };
331 </script>
332</body>
333</html>
334```
335
336## Template: NFT Mint UI (721 Hook)
337
338```html
339<!DOCTYPE html>
340<html lang="en">
341<head>
342 <meta charset="UTF-8">
343 <meta name="viewport" content="width=device-width, initial-scale=1.0">
344 <title>Mint NFT</title>
345 <link rel="stylesheet" href="/shared/styles.css">
346 <style>
347 body { max-width: 640px; margin: 0 auto; }
348 .tiers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
349 .tier-card { cursor: pointer; transition: border-color 0.2s; }
350 .tier-card:hover, .tier-card.selected { border-color: var(--jb-yellow); }
351 .tier-price { font-size: 1.25rem; font-weight: 600; color: var(--jb-yellow); }
352 .tier-remaining { font-size: 0.875rem; color: var(--text-muted); }
353 </style>
354</head>
355<body>
356 <h1>Mint NFT</h1>
357
358 <div class="card">
359 <button id="connect-btn" class="btn" onclick="connectWallet()">Connect Wallet</button>
360 <div id="wallet-status" class="hidden">
361 <div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
362 </div>
363 </div>
364
365 <div id="tiers-container" class="tiers-grid"></div>
366
367 <div class="card hidden" id="selected-tier">
368 <h3 id="tier-name"></h3>
369 <div class="stat-row"><span class="stat-label">Price</span><span class="stat-value tier-price" id="tier-price"></span></div>
370 <div class="stat-row"><span class="stat-label">Remaining</span><span class="stat-value" id="tier-remaining"></span></div>
371 <button class="btn" onclick="mint()">Mint for <span id="mint-price"></span> ETH</button>
372 </div>
373
374 <div id="tx-status" class="card hidden"></div>
375
376 <script type="module">
377 import { createPublicClient, createWalletClient, http, custom, parseEther, encodeAbiParameters } from 'https://esm.sh/viem';
378 import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
379 import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
380
381 const PROJECT_ID = 1n;
382 const CHAIN_ID = 1;
383 const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
384 const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
385
386 const TERMINAL_ABI = [
387 { name: 'pay', type: 'function', stateMutability: 'payable',
388 inputs: [
389 { name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
390 { name: 'amount', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
391 { name: 'minReturnedTokens', type: 'uint256' }, { name: 'memo', type: 'string' },
392 { name: 'metadata', type: 'bytes' }
393 ],
394 outputs: [{ type: 'uint256' }]
395 }
396 ];
397
398 const TIERS = [
399 { id: 1, name: 'Common', price: '0.01', remaining: 100 },
400 { id: 2, name: 'Rare', price: '0.1', remaining: 50 },
401 { id: 3, name: 'Legendary', price: '1.0', remaining: 10 }
402 ];
403
404 let publicClient, walletClient, address, selectedTier = null;
405
406 function renderTiers() {
407 document.getElementById('tiers-container').innerHTML = TIERS.map(tier => `
408 <div class="card tier-card" data-id="${tier.id}" onclick="selectTier(${tier.id})">
409 <h3>${tier.name}</h3>
410 <div class="tier-price">${tier.price} ETH</div>
411 <div class="tier-remaining">${tier.remaining} left</div>
412 </div>
413 `).join('');
414 }
415
416 window.selectTier = function(tierId) {
417 document.querySelectorAll('.tier-card').forEach(c => c.classList.remove('selected'));
418 document.querySelector(`[data-id="${tierId}"]`).classList.add('selected');
419
420 selectedTier = TIERS.find(t => t.id === tierId);
421 document.getElementById('tier-name').textContent = selectedTier.name;
422 document.getElementById('tier-price').textContent = selectedTier.price + ' ETH';
423 document.getElementById('tier-remaining').textContent = selectedTier.remaining;
424 document.getElementById('mint-price').textContent = selectedTier.price;
425 document.getElementById('selected-tier').classList.remove('hidden');
426 };
427
428 window.connectWallet = async function() {
429 if (!window.ethereum) { alert('Please install MetaMask'); return; }
430
431 const chain = CHAINS[CHAIN_ID];
432 publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
433 walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
434
435 const [addr] = await walletClient.requestAddresses();
436 address = addr;
437
438 document.getElementById('wallet-address').textContent = truncateAddress(address);
439 document.getElementById('wallet-status').classList.remove('hidden');
440 document.getElementById('connect-btn').classList.add('hidden');
441 };
442
443 window.mint = async function() {
444 if (!selectedTier || !address) return;
445
446 const metadata = encodeAbiParameters(
447 [{ type: 'bytes4' }, { type: 'bool' }, { type: 'uint16[]' }],
448 ['0x00000000', true, [selectedTier.id]]
449 );
450
451 const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
452 const value = parseEther(selectedTier.price);
453
454 document.getElementById('tx-status').classList.remove('hidden');
455 document.getElementById('tx-status').textContent = 'Please confirm in wallet...';
456
457 try {
458 const hash = await walletClient.writeContract({
459 address: terminal,
460 abi: TERMINAL_ABI,
461 functionName: 'pay',
462 args: [PROJECT_ID, NATIVE_TOKEN, value, address, 0n, '', metadata],
463 value,
464 account: address
465 });
466
467 document.getElementById('tx-status').innerHTML = `Transaction sent... <a href="${getTxUrl(CHAIN_ID, hash)}" target="_blank">View</a>`;
468 await publicClient.waitForTransactionReceipt({ hash });
469 document.getElementById('tx-status').textContent = 'NFT minted!';
470 } catch (error) {
471 document.getElementById('tx-status').textContent = error.shortMessage || error.message;
472 }
473 };
474
475 renderTiers();
476 </script>
477</body>
478</html>
479```
480
481## Template: Project Admin UI
482
483```html
484<!DOCTYPE html>
485<html lang="en">
486<head>
487 <meta charset="UTF-8">
488 <meta name="viewport" content="width=device-width, initial-scale=1.0">
489 <title>Project Admin</title>
490 <link rel="stylesheet" href="/shared/styles.css">
491 <style>
492 body { max-width: 640px; margin: 0 auto; }
493 .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
494 h2 { font-size: 1rem; color: var(--text-muted); margin: 1rem 0 0.75rem; }
495 .tab-content { display: none; }
496 .tab-content.active { display: block; }
497 .splits-preview { background: var(--bg-primary); padding: 0.75rem; border-radius: 4px; margin-bottom: 1rem; font-size: 0.875rem; }
498 </style>
499</head>
500<body>
501 <h1>Project #<span id="project-id">1</span> Admin</h1>
502 <p class="subtitle">Manage treasury operations</p>
503
504 <div class="card">
505 <button id="connect-btn" class="btn" onclick="connectWallet()">Connect Wallet</button>
506 <div id="wallet-status" class="hidden">
507 <div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
508 <div class="stat-row"><span class="stat-label">Owner Status</span><span class="stat-value" id="owner-status">Checking...</span></div>
509 </div>
510 </div>
511
512 <div class="card" id="treasury-card">
513 <h2>Treasury Status</h2>
514 <div class="stat-row"><span class="stat-label">Balance</span><span class="stat-value" id="treasury-balance">-</span></div>
515 <div class="stat-row"><span class="stat-label">Distributable</span><span class="stat-value" id="distributable">-</span></div>
516 <div class="stat-row"><span class="stat-label">Payout Limit</span><span class="stat-value" id="payout-limit">-</span></div>
517 <div class="stat-row"><span class="stat-label">Current Cycle</span><span class="stat-value" id="current-cycle">-</span></div>
518 </div>
519
520 <div class="tabs">
521 <div class="tab active" onclick="showTab('payouts')">Send Payouts</div>
522 <div class="tab" onclick="showTab('allowance')">Use Allowance</div>
523 <div class="tab" onclick="showTab('reserved')">Reserved</div>
524 </div>
525
526 <div id="payouts-tab" class="tab-content active">
527 <div class="card">
528 <h2>Distribute to Splits</h2>
529 <p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem;">Send funds to configured split recipients.</p>
530 <label>Amount to Distribute (ETH)</label>
531 <input type="number" id="payout-amount" placeholder="0.0" step="0.01">
532 <button class="btn btn-secondary" onclick="setMaxPayout()" style="margin-bottom: 1rem;">Max Available</button>
533 <div class="splits-preview">
534 <strong>Split Recipients:</strong>
535 <div id="splits-list" style="margin-top: 0.5rem; color: var(--text-muted);">Loading...</div>
536 </div>
537 <button class="btn" onclick="sendPayouts()">Send Payouts</button>
538 </div>
539 </div>
540
541 <div id="allowance-tab" class="tab-content">
542 <div class="card">
543 <h2>Use Surplus Allowance</h2>
544 <p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem;">Withdraw from surplus (discretionary spending).</p>
545 <div class="stat-row"><span class="stat-label">Remaining Allowance</span><span class="stat-value" id="surplus-allowance">-</span></div>
546 <label>Amount to Withdraw (ETH)</label>
547 <input type="number" id="allowance-amount" placeholder="0.0" step="0.01">
548 <label>Beneficiary Address</label>
549 <input type="text" id="allowance-beneficiary" placeholder="0x... (defaults to connected wallet)">
550 <button class="btn" onclick="useAllowance()">Withdraw from Surplus</button>
551 </div>
552 </div>
553
554 <div id="reserved-tab" class="tab-content">
555 <div class="card">
556 <h2>Distribute Reserved Tokens</h2>
557 <p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem;">Mint and distribute accumulated reserved tokens.</p>
558 <div class="stat-row"><span class="stat-label">Pending Reserved Tokens</span><span class="stat-value" id="pending-reserved">-</span></div>
559 <button class="btn" onclick="sendReservedTokens()">Distribute Reserved Tokens</button>
560 </div>
561 </div>
562
563 <div id="tx-status" class="card hidden">
564 <span id="tx-state"></span>
565 <a id="tx-link" href="#" target="_blank" class="hidden">View transaction</a>
566 </div>
567
568 <script type="module">
569 import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther } from 'https://esm.sh/viem';
570 import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
571 import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
572
573 const PROJECT_ID = 1n;
574 const CHAIN_ID = 1;
575 const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
576 const NATIVE_TOKEN = '0x000000000000000000000000000000000000EEEe';
577
578 const TERMINAL_ABI = [
579 { name: 'sendPayoutsOf', type: 'function', stateMutability: 'nonpayable',
580 inputs: [
581 { name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
582 { name: 'amount', type: 'uint256' }, { name: 'currency', type: 'uint256' },
583 { name: 'minTokensPaidOut', type: 'uint256' }
584 ],
585 outputs: [{ type: 'uint256' }]
586 },
587 { name: 'useAllowanceOf', type: 'function', stateMutability: 'nonpayable',
588 inputs: [
589 { name: 'projectId', type: 'uint256' }, { name: 'token', type: 'address' },
590 { name: 'amount', type: 'uint256' }, { name: 'currency', type: 'uint256' },
591 { name: 'minTokensPaidOut', type: 'uint256' }, { name: 'beneficiary', type: 'address' },
592 { name: 'feeBeneficiary', type: 'address' }, { name: 'memo', type: 'string' }
593 ],
594 outputs: [{ type: 'uint256' }]
595 }
596 ];
597
598 const CONTROLLER_ABI = [
599 { name: 'sendReservedTokensToSplitsOf', type: 'function', stateMutability: 'nonpayable',
600 inputs: [{ name: 'projectId', type: 'uint256' }],
601 outputs: [{ type: 'uint256' }]
602 }
603 ];
604
605 const PROJECTS_ABI = [
606 { name: 'ownerOf', type: 'function', stateMutability: 'view',
607 inputs: [{ name: 'tokenId', type: 'uint256' }],
608 outputs: [{ type: 'address' }]
609 }
610 ];
611
612 let publicClient, walletClient, address;
613
614 document.getElementById('project-id').textContent = PROJECT_ID.toString();
615
616 window.showTab = function(tabName) {
617 document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
618 document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
619 event.target.classList.add('active');
620 document.getElementById(`${tabName}-tab`).classList.add('active');
621 };
622
623 window.connectWallet = async function() {
624 if (!window.ethereum) { alert('Please install MetaMask'); return; }
625
626 const chain = CHAINS[CHAIN_ID];
627 publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
628 walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
629
630 const [addr] = await walletClient.requestAddresses();
631 address = addr;
632
633 document.getElementById('wallet-address').textContent = truncateAddress(address);
634 document.getElementById('wallet-status').classList.remove('hidden');
635 document.getElementById('connect-btn').classList.add('hidden');
636
637 const projects = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBProjects;
638 const owner = await publicClient.readContract({ address: projects, abi: PROJECTS_ABI, functionName: 'ownerOf', args: [PROJECT_ID] });
639 const isOwner = owner.toLowerCase() === address.toLowerCase();
640 document.getElementById('owner-status').textContent = isOwner ? 'Owner' : 'Not Owner';
641
642 await loadTreasuryStats();
643 };
644
645 async function loadTreasuryStats() {
646 document.getElementById('treasury-balance').textContent = '10.5 ETH';
647 document.getElementById('distributable').textContent = '8.0 ETH';
648 document.getElementById('payout-limit').textContent = '8.0 ETH / cycle';
649 document.getElementById('current-cycle').textContent = '3';
650 document.getElementById('surplus-allowance').textContent = '2.5 ETH';
651 document.getElementById('pending-reserved').textContent = '50,000 tokens';
652 document.getElementById('splits-list').innerHTML = '0x1234...5678 (50%), Project #2 (50%)';
653 }
654
655 window.setMaxPayout = () => document.getElementById('payout-amount').value = '8.0';
656
657 window.sendPayouts = async function() {
658 const amount = document.getElementById('payout-amount').value;
659 if (!amount || parseFloat(amount) <= 0) { alert('Enter an amount'); return; }
660
661 const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
662 showTxPending('Please confirm in wallet...');
663
664 try {
665 const hash = await walletClient.writeContract({
666 address: terminal,
667 abi: TERMINAL_ABI,
668 functionName: 'sendPayoutsOf',
669 args: [PROJECT_ID, NATIVE_TOKEN, parseEther(amount), 0n, 0n],
670 account: address
671 });
672 showTxSent(hash);
673 await publicClient.waitForTransactionReceipt({ hash });
674 showTxConfirmed();
675 await loadTreasuryStats();
676 } catch (error) { showTxError(error); }
677 };
678
679 window.useAllowance = async function() {
680 const amount = document.getElementById('allowance-amount').value;
681 const beneficiary = document.getElementById('allowance-beneficiary').value || address;
682 if (!amount || parseFloat(amount) <= 0) { alert('Enter an amount'); return; }
683
684 const terminal = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBMultiTerminal;
685 showTxPending('Please confirm in wallet...');
686
687 try {
688 const hash = await walletClient.writeContract({
689 address: terminal,
690 abi: TERMINAL_ABI,
691 functionName: 'useAllowanceOf',
692 args: [PROJECT_ID, NATIVE_TOKEN, parseEther(amount), 0n, 0n, beneficiary, address, 'Surplus allowance withdrawal'],
693 account: address
694 });
695 showTxSent(hash);
696 await publicClient.waitForTransactionReceipt({ hash });
697 showTxConfirmed();
698 await loadTreasuryStats();
699 } catch (error) { showTxError(error); }
700 };
701
702 window.sendReservedTokens = async function() {
703 const controller = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBController;
704 showTxPending('Please confirm in wallet...');
705
706 try {
707 const hash = await walletClient.writeContract({
708 address: controller,
709 abi: CONTROLLER_ABI,
710 functionName: 'sendReservedTokensToSplitsOf',
711 args: [PROJECT_ID],
712 account: address
713 });
714 showTxSent(hash);
715 await publicClient.waitForTransactionReceipt({ hash });
716 showTxConfirmed();
717 await loadTreasuryStats();
718 } catch (error) { showTxError(error); }
719 };
720
721 function showTxPending(msg) {
722 document.getElementById('tx-status').classList.remove('hidden');
723 document.getElementById('tx-state').textContent = msg;
724 document.getElementById('tx-link').classList.add('hidden');
725 }
726 function showTxSent(hash) {
727 document.getElementById('tx-state').textContent = 'Transaction sent...';
728 const link = document.getElementById('tx-link');
729 link.href = getTxUrl(CHAIN_ID, hash);
730 link.classList.remove('hidden');
731 }
732 function showTxConfirmed() { document.getElementById('tx-state').textContent = 'Transaction confirmed!'; }
733 function showTxError(error) { document.getElementById('tx-state').textContent = error.shortMessage || error.message; }
734 </script>
735</body>
736</html>
737```
738
739## Template: Claim Tokens UI
740
741```html
742<!DOCTYPE html>
743<html lang="en">
744<head>
745 <meta charset="UTF-8">
746 <meta name="viewport" content="width=device-width, initial-scale=1.0">
747 <title>Claim Tokens</title>
748 <link rel="stylesheet" href="/shared/styles.css">
749 <style>
750 body { max-width: 480px; margin: 0 auto; }
751 .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
752 h2 { font-size: 1rem; color: var(--text-muted); margin-bottom: 1rem; }
753 .info { background: var(--bg-primary); padding: 0.75rem; border-radius: 4px; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
754 .warning-card { border-color: var(--accent) !important; }
755 .warning-card p { font-size: 0.875rem; }
756 </style>
757</head>
758<body>
759 <h1>Claim Tokens</h1>
760 <p class="subtitle">Convert credits to ERC-20 tokens</p>
761
762 <div class="card">
763 <button id="connect-btn" class="btn" onclick="connectWallet()">Connect Wallet</button>
764 <div id="wallet-status" class="hidden">
765 <div class="stat-row"><span class="stat-label">Connected</span><span class="stat-value" id="wallet-address"></span></div>
766 </div>
767 </div>
768
769 <div class="card">
770 <h2>Your Balances</h2>
771 <div class="stat-row"><span class="stat-label">Credits (unclaimed)</span><span class="stat-value" id="credit-balance">-</span></div>
772 <div class="stat-row"><span class="stat-label">ERC-20 Tokens</span><span class="stat-value" id="token-balance">-</span></div>
773 <div class="stat-row"><span class="stat-label">Total Balance</span><span class="stat-value" id="total-balance">-</span></div>
774 </div>
775
776 <div class="card" id="claim-section">
777 <div class="info">Credits are stored in the Juicebox protocol. Claiming converts them to ERC-20 tokens in your wallet.</div>
778 <label>Amount to Claim</label>
779 <input type="number" id="claim-amount" placeholder="0">
780 <button class="btn btn-secondary" onclick="setMaxClaim()">Claim All</button>
781 <button id="claim-btn" class="btn" onclick="claimTokens()" disabled>Claim Tokens</button>
782 </div>
783
784 <div class="card warning-card hidden" id="no-token-warning">
785 <p>This project hasn't deployed an ERC-20 token yet. Credits cannot be claimed until the project owner deploys one.</p>
786 </div>
787
788 <div id="tx-status" class="card hidden">
789 <span id="tx-state"></span>
790 <a id="tx-link" href="#" target="_blank" class="hidden">View transaction</a>
791 </div>
792
793 <script type="module">
794 import { createPublicClient, createWalletClient, http, custom, formatEther, parseEther, zeroAddress } from 'https://esm.sh/viem';
795 import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
796 import { CHAIN_CONFIGS, truncateAddress, getTxUrl } from '/shared/wallet-utils.js';
797
798 const PROJECT_ID = 1n;
799 const CHAIN_ID = 1;
800 const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
801
802 const CONTROLLER_ABI = [
803 { name: 'claimTokensFor', type: 'function', stateMutability: 'nonpayable',
804 inputs: [
805 { name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' },
806 { name: 'tokenCount', type: 'uint256' }, { name: 'beneficiary', type: 'address' }
807 ],
808 outputs: []
809 }
810 ];
811
812 const TOKENS_ABI = [
813 { name: 'creditBalanceOf', type: 'function', stateMutability: 'view',
814 inputs: [{ name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' }],
815 outputs: [{ type: 'uint256' }]
816 },
817 { name: 'tokenOf', type: 'function', stateMutability: 'view',
818 inputs: [{ name: 'projectId', type: 'uint256' }],
819 outputs: [{ type: 'address' }]
820 },
821 { name: 'totalBalanceOf', type: 'function', stateMutability: 'view',
822 inputs: [{ name: 'holder', type: 'address' }, { name: 'projectId', type: 'uint256' }],
823 outputs: [{ type: 'uint256' }]
824 }
825 ];
826
827 let publicClient, walletClient, address, creditBalance = 0n;
828
829 window.connectWallet = async function() {
830 if (!window.ethereum) { alert('Please install MetaMask'); return; }
831
832 const chain = CHAINS[CHAIN_ID];
833 publicClient = createPublicClient({ chain, transport: http(CHAIN_CONFIGS[CHAIN_ID]?.rpc) });
834 walletClient = createWalletClient({ chain, transport: custom(window.ethereum) });
835
836 const [addr] = await walletClient.requestAddresses();
837 address = addr;
838
839 document.getElementById('wallet-address').textContent = truncateAddress(address);
840 document.getElementById('wallet-status').classList.remove('hidden');
841 document.getElementById('connect-btn').classList.add('hidden');
842
843 await loadBalances();
844 };
845
846 async function loadBalances() {
847 const tokens = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBTokens;
848
849 const tokenAddr = await publicClient.readContract({ address: tokens, abi: TOKENS_ABI, functionName: 'tokenOf', args: [PROJECT_ID] });
850 const hasToken = tokenAddr !== zeroAddress;
851
852 if (!hasToken) {
853 document.getElementById('claim-section').classList.add('hidden');
854 document.getElementById('no-token-warning').classList.remove('hidden');
855 }
856
857 creditBalance = await publicClient.readContract({ address: tokens, abi: TOKENS_ABI, functionName: 'creditBalanceOf', args: [address, PROJECT_ID] });
858 const totalBalance = await publicClient.readContract({ address: tokens, abi: TOKENS_ABI, functionName: 'totalBalanceOf', args: [address, PROJECT_ID] });
859 const tokenBalance = totalBalance - creditBalance;
860
861 document.getElementById('credit-balance').textContent = parseInt(formatEther(creditBalance)).toLocaleString();
862 document.getElementById('token-balance').textContent = parseInt(formatEther(tokenBalance)).toLocaleString();
863 document.getElementById('total-balance').textContent = parseInt(formatEther(totalBalance)).toLocaleString();
864
865 if (hasToken && creditBalance > 0n) document.getElementById('claim-btn').disabled = false;
866 }
867
868 window.setMaxClaim = () => document.getElementById('claim-amount').value = parseInt(formatEther(creditBalance));
869
870 window.claimTokens = async function() {
871 const amount = document.getElementById('claim-amount').value;
872 if (!amount || parseInt(amount) <= 0) { alert('Enter an amount'); return; }
873
874 const controller = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBController;
875 showTxPending('Please confirm in wallet...');
876
877 try {
878 const hash = await walletClient.writeContract({
879 address: controller,
880 abi: CONTROLLER_ABI,
881 functionName: 'claimTokensFor',
882 args: [address, PROJECT_ID, parseEther(amount), address],
883 account: address
884 });
885 showTxSent(hash);
886 await publicClient.waitForTransactionReceipt({ hash });
887 showTxConfirmed();
888 await loadBalances();
889 } catch (error) { showTxError(error); }
890 };
891
892 function showTxPending(msg) {
893 document.getElementById('tx-status').classList.remove('hidden');
894 document.getElementById('tx-state').textContent = msg;
895 document.getElementById('tx-link').classList.add('hidden');
896 }
897 function showTxSent(hash) {
898 document.getElementById('tx-state').textContent = 'Transaction sent...';
899 const link = document.getElementById('tx-link');
900 link.href = getTxUrl(CHAIN_ID, hash);
901 link.classList.remove('hidden');
902 }
903 function showTxConfirmed() { document.getElementById('tx-state').textContent = 'Tokens claimed!'; }
904 function showTxError(error) { document.getElementById('tx-state').textContent = error.shortMessage || error.message; }
905 </script>
906</body>
907</html>
908```
909
910## Template: Project Dashboard UI
911
912```html
913<!DOCTYPE html>
914<html lang="en">
915<head>
916 <meta charset="UTF-8">
917 <meta name="viewport" content="width=device-width, initial-scale=1.0">
918 <title>Project Dashboard</title>
919 <link rel="stylesheet" href="/shared/styles.css">
920 <style>
921 body { max-width: 800px; margin: 0 auto; }
922 .subtitle { color: var(--text-muted); margin-bottom: 2rem; }
923 .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
924 .metric-card { text-align: center; }
925 .metric-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
926 .metric-value { font-size: 1.5rem; font-weight: 600; }
927 .metric-sub { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }
928 h2 { font-size: 1rem; color: var(--text-muted); margin-bottom: 1rem; }
929 </style>
930</head>
931<body>
932 <h1 id="project-name">Loading...</h1>
933 <p class="subtitle">Project #<span id="project-id">1</span></p>
934
935 <div class="grid">
936 <div class="card metric-card">
937 <div class="metric-label">Treasury Balance</div>
938 <div class="metric-value" id="treasury-balance">-</div>
939 <div class="metric-sub">ETH</div>
940 </div>
941 <div class="card metric-card">
942 <div class="metric-label">Token Supply</div>
943 <div class="metric-value" id="token-supply">-</div>
944 <div class="metric-sub">tokens issued</div>
945 </div>
946 <div class="card metric-card">
947 <div class="metric-label">Token Holders</div>
948 <div class="metric-value" id="holder-count">-</div>
949 <div class="metric-sub">unique addresses</div>
950 </div>
951 <div class="card metric-card">
952 <div class="metric-label">Current Cycle</div>
953 <div class="metric-value" id="current-cycle">-</div>
954 <div class="metric-sub" id="cycle-end">-</div>
955 </div>
956 </div>
957
958 <div class="card">
959 <h2>Current Ruleset</h2>
960 <div class="stat-row"><span class="stat-label">Duration</span><span class="stat-value" id="duration">-</span></div>
961 <div class="stat-row"><span class="stat-label">Issuance (tokens/ETH)</span><span class="stat-value" id="weight">-</span></div>
962 <div class="stat-row"><span class="stat-label">Reserved Rate</span><span class="stat-value" id="reserved-rate">-</span></div>
963 <div class="stat-row"><span class="stat-label">Cash Out Tax Rate</span><span class="stat-value" id="cash-out-tax">-</span></div>
964 <div class="stat-row"><span class="stat-label">Payout Limit</span><span class="stat-value" id="payout-limit">-</span></div>
965 <div class="stat-row"><span class="stat-label">Data Hook</span><span class="stat-value" id="data-hook">-</span></div>
966 </div>
967
968 <div class="card">
969 <h2>Project Owner</h2>
970 <div class="stat-row">
971 <span class="stat-label">Address</span>
972 <span class="stat-value"><a id="owner-link" href="#" target="_blank"><span id="owner-address">-</span></a></span>
973 </div>
974 </div>
975
976 <script type="module">
977 import { createPublicClient, http, formatEther, zeroAddress } from 'https://esm.sh/viem';
978 import { mainnet, optimism, base, arbitrum, sepolia } from 'https://esm.sh/viem/chains';
979 import { CHAIN_CONFIGS, truncateAddress, getAddressUrl } from '/shared/wallet-utils.js';
980
981 const PROJECT_ID = 1n;
982 const CHAIN_ID = 1;
983 const CHAINS = { 1: mainnet, 10: optimism, 8453: base, 42161: arbitrum, 11155111: sepolia };
984
985 const CONTROLLER_ABI = [
986 { name: 'currentRulesetOf', type: 'function', stateMutability: 'view',
987 inputs: [{ name: 'projectId', type: 'uint256' }],
988 outputs: [
989 { name: 'ruleset', type: 'tuple', components: [
990 { name: 'cycleNumber', type: 'uint256' }, { name: 'id', type: 'uint256' },
991 { name: 'basedOnId', type: 'uint256' }, { name: 'start', type: 'uint256' },
992 { name: 'duration', type: 'uint256' }, { name: 'weight', type: 'uint256' },
993 { name: 'weightCutPercent', type: 'uint256' }, { name: 'approvalHook', type: 'address' },
994 { name: 'metadata', type: 'uint256' }
995 ]},
996 { name: 'metadata', type: 'tuple', components: [
997 { name: 'reservedRate', type: 'uint256' }, { name: 'cashOutTaxRate', type: 'uint256' },
998 { name: 'baseCurrency', type: 'uint256' }, { name: 'pausePay', type: 'bool' },
999 { name: 'pauseCashOut', type: 'bool' }, { name: 'pauseTransfers', type: 'bool' },
1000 { name: 'allowOwnerMinting', type: 'bool' }, { name: 'allowTerminalMigration', type: 'bool' },
1001 { name: 'allowSetTerminals', type: 'bool' }, { name: 'allowSetController', type: 'bool' },
1002 { name: 'allowAddAccountingContexts', type: 'bool' }, { name: 'allowAddPriceFeed', type: 'bool' },
1003 { name: 'ownerMustSendPayouts', type: 'bool' }, { name: 'holdFees', type: 'bool' },
1004 { name: 'useTotalSurplusForCashOuts', type: 'bool' }, { name: 'useDataHookForPay', type: 'bool' },
1005 { name: 'useDataHookForCashOut', type: 'bool' }, { name: 'dataHook', type: 'address' },
1006 { name: 'metadata', type: 'uint256' }
1007 ]}
1008 ]
1009 },
1010 { name: 'totalTokenSupplyWithReservedTokensOf', type: 'function', stateMutability: 'view',
1011 inputs: [{ name: 'projectId', type: 'uint256' }],
1012 outputs: [{ type: 'uint256' }]
1013 }
1014 ];
1015
1016 const PROJECTS_ABI = [
1017 { name: 'ownerOf', type: 'function', stateMutability: 'view',
1018 inputs: [{ name: 'tokenId', type: 'uint256' }],
1019 outputs: [{ type: 'address' }]
1020 }
1021 ];
1022
1023 document.getElementById('project-id').textContent = PROJECT_ID.toString();
1024
1025 async function loadProjectData() {
1026 const chain = CHAINS[CHAIN_ID];
1027 const rpc = CHAIN_CONFIGS[CHAIN_ID]?.rpc || chain.rpcUrls.default.http[0];
1028 const publicClient = createPublicClient({ chain, transport: http(rpc) });
1029
1030 const controller = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBController;
1031 const projects = CHAIN_CONFIGS[CHAIN_ID]?.contracts?.JBProjects;
1032
1033 try {
1034 const [rulesetData, totalSupply, owner] = await Promise.all([
1035 publicClient.readContract({ address: controller, abi: CONTROLLER_ABI, functionName: 'currentRulesetOf', args: [PROJECT_ID] }),
1036 publicClient.readContract({ address: controller, abi: CONTROLLER_ABI, functionName: 'totalTokenSupplyWithReservedTokensOf', args: [PROJECT_ID] }),
1037 publicClient.readContract({ address: projects, abi: PROJECTS_ABI, functionName: 'ownerOf', args: [PROJECT_ID] })
1038 ]);
1039
1040 const [ruleset, metadata] = rulesetData;
1041
1042 document.getElementById('project-name').textContent = `Project #${PROJECT_ID}`;
1043 document.getElementById('token-supply').textContent = parseInt(formatEther(totalSupply)).toLocaleString();
1044 document.getElementById('current-cycle').textContent = ruleset.cycleNumber.toString();
1045 document.getElementById('duration').textContent = ruleset.duration > 0 ? `${Number(ruleset.duration) / 86400} days` : 'Indefinite';
1046 document.getElementById('weight').textContent = parseInt(formatEther(ruleset.weight)).toLocaleString();
1047 document.getElementById('reserved-rate').textContent = `${Number(metadata.reservedRate) / 100}%`;
1048 document.getElementById('cash-out-tax').textContent = `${Number(metadata.cashOutTaxRate) / 100}%`;
1049 document.getElementById('data-hook').textContent = metadata.dataHook === zeroAddress ? 'None' : truncateAddress(metadata.dataHook);
1050 document.getElementById('owner-address').textContent = truncateAddress(owner);
1051 document.getElementById('owner-link').href = getAddressUrl(CHAIN_ID, owner);
1052
1053 document.getElementById('treasury-balance').textContent = '-';
1054 document.getElementById('holder-count').textContent = '-';
1055 document.getElementById('payout-limit').textContent = '-';
1056 } catch (error) {
1057 console.error('Error loading project data:', error);
1058 document.getElementById('project-name').textContent = 'Error loading project';
1059 }
1060 }
1061
1062 loadProjectData();
1063 </script>
1064</body>
1065</html>
1066```
1067
1068## Generation Guidelines
1069
10701. **Project ID as config** - Make it easy to change which project the UI targets
10712. **Network switching** - Detect wrong network and prompt user to switch
10723. **Real-time previews** - Show expected token amounts before transaction
10734. **Error handling** - Catch wallet rejections and contract reverts gracefully
10745. **Loading states** - Disable buttons and show spinners during transactions
10756. **Read-only mode** - Support viewing data without wallet connection
1076
1077## Fetching Project Data
1078
1079To show real project stats, query the contracts:
1080
1081```javascript
1082async function getProjectStats(projectId) {
1083 const controller = CHAIN_CONFIGS[chainId]?.contracts?.JBController;
1084
1085 const [ruleset, metadata] = await publicClient.readContract({
1086 address: controller,
1087 abi: CONTROLLER_ABI,
1088 functionName: 'currentRulesetOf',
1089 args: [projectId]
1090 });
1091
1092 return {
1093 weight: ruleset.weight,
1094 duration: ruleset.duration,
1095 reservedRate: metadata.reservedRate,
1096 cashOutTaxRate: metadata.cashOutTaxRate
1097 };
1098}
1099```
1100
1101## Fetching Data with Bendystraw
1102
1103Instead of querying contracts directly, use Bendystraw for faster, indexed data:
1104
1105```javascript
1106// Bendystraw client (use server-side proxy to hide API key)
1107async function bendystrawQuery(query, variables = {}) {
1108 const response = await fetch('/api/bendystraw', {
1109 method: 'POST',
1110 headers: { 'Content-Type': 'application/json' },
1111 body: JSON.stringify({ query, variables })
1112 });
1113 return (await response.json()).data;
1114}
1115
1116// Get project stats
1117async function getProjectStats(projectId, chainId) {
1118 return bendystrawQuery(`
1119 query($projectId: Int!, $chainId: Int!) {
1120 project(projectId: $projectId, chainId: $chainId) {
1121 name handle logoUri owner
1122 balance volume volumeUsd
1123 tokenSupply token tokenSymbol
1124 paymentsCount contributorsCount
1125 trendingScore trendingVolume
1126 }
1127 }
1128 `, { projectId, chainId });
1129}
1130```
1131
1132Contact [@peripheralist](https://x.com/peripheralist) for an API key.
1133
1134## Related Skills
1135
1136- `/jb-deploy-ui` - UIs for deploying new projects
1137- `/jb-omnichain-ui` - Multi-chain UIs with Relayr & Bendystraw
1138- `/jb-query` - Direct contract queries (when Bendystraw unavailable)
1139- `/jb-v5-api` - Contract function signatures