Example dApp: trac-dapp-example (Wallet + Peer RPC)
This workspace contains a minimal reference dApp that demonstrates the intended client flow:
dApp talks to a trac-peer HTTP RPC (a URL)
dApp fetches schema + nonce + tx context
wallet signs the contract tx (window.tracnetwork.signTracTx(...))
dApp submits sim=true then sim=false
dApp reads contract state via GET /v1/state
In this workspace, that dApp lives in the folder:
For documentation purposes we refer to it as trac-dapp-example (it is a “catch creatures” demo).
1) Start a peer RPC node (the backend the dApp talks to)
You need a trac-peer node running with RPC enabled.
Example:
cd trac-peer
npm run peer:run -- \
--msb-bootstrap=<MSB_BOOTSTRAP_HEX32> \
--msb-channel=<MSB_CHANNEL> \
--peer-store-name=peer-rpc \
--msb-store-name=peer-rpc-msb \
--subnet-channel=tuxedex-v1 \
--rpc \
--api-tx-exposed \
--rpc-host 127.0.0.1 \
--rpc-port 5001
Quick checks:
Notes:
--api-tx-exposed is required for the dApp to submit POST /v1/contract/tx.
The peer must have enough MSB fee balance for contract txs; fund its printed Peer MSB address on MSB.
2) Install and run the dApp
The Next.js server proxies requests to the peer RPC via env vars:
Open:
3) Wallet requirements
The dApp expects a browser wallet extension that injects:
and supports:
In this workspace, see:
4) What happens when you click “Catch”
The dApp:
calls GET /v1/contract/schema (checks the contract supports catch)
calls GET /v1/contract/nonce
calls GET /v1/contract/tx/context
builds the wallet signing payload (contractTx) with:
{ prepared_command, nonce, context }
calls window.tracnetwork.signTracTx(contractTx) to get { tx, signature }
calls POST /v1/contract/tx with sim=true
calls POST /v1/contract/tx with sim=false
polls state under:
app/tuxedex/<pubKeyHex> (unconfirmed view)
The peer’s demo contract writes the user’s “dex” under that key.
5) Troubleshooting
“Wallet extension not detected”
The dApp can’t find window.tracnetwork. Install/enable the wallet extension and reload the page.
“Requester address not found in state” / insufficient fee balance
Fund the wallet’s MSB address (the requester) on MSB so it can pay MSB fees for type=12 contract txs.
Also ensure the peer’s own MSB address is funded so it can operate reliably.
Wrong peer / wrong contract
If GET /v1/contract/schema does not include "catch" in contract.txTypes, you’re pointing the dApp at a peer running a different contract/app.
Last updated