In the prototype demo, the +100 Sats are just arcade score points to keep the gameplay loop risk-free while testing the physics and feel.
But the iframe architecture is already pre-wired to support real money via two clean mechanics:
Here is how the postMessage handshake looks in code to make both sides real right now 👇"
Part 2: How to Add Real Payments to the Code
To turn the simulation into real transactions inside Treechat, you implement a two-way handshake using window.parent.postMessage and window.addEventListener('message').
Step 1: The "Insert Coin" (Pay-to-Play) Handshake
Instead of starting instantly when the player hits "START", the game asks Treechat to charge a micro-fee (e.g. 50 Sats):
// Inside index.html — when user taps "START" or "INSERT COIN"
function requestInsertCoinPayment(amountSats = 50) {
if (window.parent && window.parent !== window) {
// Show "Awaiting Wallet Approval..." on screen
document.getElementById('overlaySubtitle').textContent =
Sending request to Treechat wallet for ${amountSats} Sats entry...;
window.parent.postMessage({
source: 'treechat-ordinal-satoshi-pang-3d',
type: 'TREECHAT_REQUEST_PAYMENT',
currency: 'SAT',
amount: amountSats,
memo: 'Insert Coin: Satoshi Pang 3D Entry'
}, '*');
} else {
// Fallback for standalone / local browser testing
startOrResumeGame();
}
}
Step 2: Listen for Payment Confirmation from Treechat
When the user approves the micropayment in the Treechat container, Treechat sends a confirmation back into the game iframe:
// Inside index.html — listener for Treechat's receipt
window.addEventListener('message', (event) => {
const data = event.data;
if (!data || typeof data !== 'object') return;
// Treechat parent confirms real Sats received
if (data.type === 'TREECHAT_PAYMENT_SUCCESS') {
console.log("Real payment confirmed! TXID:", data.txid);
// Unlock game with real credits
sound.sfxStageClear();
gameState.lives = 3;
gameState.running = true;
gameState.paused = false;
document.getElementById('menuOverlay').classList.add('hidden');
loadCityStage(gameState.cityIndex);
}
else if (data.type === 'TREECHAT_PAYMENT_REJECTED') {
document.getElementById('overlaySubtitle').textContent =
"Payment canceled. Insert coin to play!";
}
});
Step 3: Paying Out Real Sats (Cash-Out or Bounties)
When a player hits a milestone (e.g., clears Wonder Layer 7 or breaks 20 Bitcoins), the game calls the claim hook you already have, passing verification data so Treechat or a tip-bot can process the payment:
function requestRealPayout(satsEarned) {
if (window.parent && window.parent !== window) {
window.parent.postMessage({
source: 'treechat-ordinal-satoshi-pang-3d',
type: 'TREECHAT_CLAIM_PAYOUT',
amountSats: satsEarned,
walletAddress: gameState.walletAddress,
// Verification tokens prevent browser tampering
stageCleared: WORLD_CITIES[gameState.cityIndex].name,
coinsBroken: gameState.coinsBrokenCount,
clientTimestamp: Date.now()
}, '*');
}
}
3 Game Mechanics That Use Real Money on Treechat
Insert Coin (50–100 Sats): Authentic 90s arcade feel. Players spend pennies to buy a run of 3 lives.
Room Jackpot / Pot: 80% of entry fees go into the "Insert Coin Room" pot. The highest weekly scorer or the first to finish Layer 7 takes the accumulated Sats.
P2P Challenge Wagers: Two players in the same Treechat channel stake 250 Sats each. Whoever survives longer or scores more takes the 500 Sats minus the room host fee.