Marketplace as a phone app (Stage A)¶
Using the backend you built in Stages 5–6 as is, you use iot-market-ui as a home screen app (PWA: Progressive Web App) on your phone. You go from purchase through VC receipt to viewing by tapping, with no command line.
What you'll do: Use iot-market-ui as a PWA on your phone and go through purchase and VC receipt
Prerequisites: Hand a credential to the buyer's wallet (Bridge / Stage 5), Step E0 of Read ServiceVC-written data with a PurchaseViewerVC (Stage 6) (deploy and public key registration)
Keep running: the Hardhat node on which you did Step E0 of Stage 6. Step M0 restarts the publisher, the bridge and iot-market-ui
What you need: PC + smartphone (with two apps installed: iw3ip-wallet and MetaMask Mobile)
Time required: approx. 30 min
Where this page belongs
- This is the fourth page of 2.4 in Part 2 (Hands-on).
- Previous page: Back the seller's identity (Seller VC / Stage 7)
- Next page: Tier the response by trust (DataUserVC / Stage T)
A PWA version that needs no command line
In this hands-on you use the backend built in Stages 5–6 as is, and use iot-market-ui
as a home screen app on iPhone/Android.
Without any command-line operation, you go from purchase through VC receipt to
viewing the data by tapping on the phone screen. Stage A refers to this smartphone app (PWA) version. There are two ways to use the phone: the PWA version on this page is called "method 1", and a native
app (React Native) with the wallet function built in is called "method 2". Method 2 is planned
as Stage 9. Stage 9 is only a plan; there is no hands-on page for it yet.
Same data as Stage 0
In Stage A, you choose what to purchase from the list of Merchandise registered by the
deploy script of Stage 6 case B and later. If you choose home/event/possible_littering
(Merchandise #2), you can confirm that the same camera events as in Stage 0
(see the Hands-on for the list of Stages)
(Share detections, not raw frames)
can be read through a purchase (PurchaseViewerVC).
home/event/flood_risk_high (Merchandise #4) has no PurchaseViewerVC
Presentation Definition registered, so you cannot get as far as viewing it.
Goals¶
- Use iot-market-ui as a PWA (Progressive Web App)
- Confirm the existing deeplink integration (publisher / iw3ip-wallet / MetaMask Mobile) as a single flow that beginners can follow without getting lost
- Confirm that the purchase history is stored locally on the device and can be accessed
later from
/my-data
What you'll learn¶
- "ホーム画面に追加" (Add to Home Screen) in iPhone Safari turns the IoT market into an app
- After a purchase, pressing the deeplink button on the
/purchased/[txHash]screen launches iw3ip-wallet, which receives the VC and then returns to the browser /my-datalists past purchases- The three steps of
/welcomelet even a first-time user get set up
Common pitfalls¶
- PWA restrictions in iOS Safari: some APIs (push notifications, Bluetooth, and so on) are restricted. This is not a problem within the scope of this hands-on
- If Universal Links / App Links are not configured on the wallet side, the automatic return to the browser after receipt does not happen. Even if it does not return, the flow is not interrupted as long as you go back to Safari manually
- localStorage is local to the device. If you use the same wallet on another device, the history is not shared
Pages to read first¶
- VC architecture overview (Part 2 / Stages 0–7, T, A, P) — the overall picture
- Hand a credential to the buyer's wallet (Bridge / Stage 5) — the hands-on the purchase flow comes from
- Back the seller's identity (Seller VC / Stage 7) — the seller-side flow
Required environment¶
- You have completed the Stage 5 and Stage 6 hands-ons (the purchase uses the Merchandise deployed and the public key registered in Stage 6 Step E0; Stage 7 is optional and only matters for the
seller_didexplanation in Step M5). If you restarted Hardhat since then, first redo Stage 6 Step E0 (start the node, deploy, register the public key, recreate the bridge) - You can start publisher + bridge + Hardhat + iot-market-ui
- iw3ip-wallet (iPhone) works
- MetaMask Mobile (the App Store app) is installed on the iPhone. You make the purchase from its built-in browser (setup is step 0 of Step M3)
$HOST_IPin commands and<HOST_IP>in URLs stand for the PC's LAN IP. In each terminal you use, first runexport HOST_IP='<your PC LAN IP>'(see the Hands-on for how to find it). Replace<HOST_IP>in URLs you type into a browser or phone with the same IP- The steps assume a Mac and an iPhone, with the course repository cloned to
~/program/Blockchain_IoT_Marketplaceand the wallet to~/program/iw3ip-wallet
Overview¶
flowchart TB
subgraph FIRST["First launch"]
F1["iPhone Safari → http://<HOST_IP>:5173/welcome"]
end
subgraph HOME["Add to Home Screen"]
H1["Safari menu → Add to Home Screen"]
H2["the IW3IP app icon is added<br>(standalone display)"]
end
subgraph LAUNCH["Launch"]
L1["tap the icon → / of iot-market-ui opens in standalone mode"]
end
subgraph BUY["Purchase"]
B1["select a product → confirm in the MetaMask Mobile in-app browser → send the tx"]
B2["automatically moves to /purchased/[txHash]"]
B3["「ウォレットで開く」 (Open in wallet) button → iw3ip-wallet launches → VC received"]
end
subgraph HIST["History + viewing"]
V1["hamburger menu → 「購入履歴 / データを見る」<br>(Purchase history / View data)"]
V2["list of past purchases in /my-data"]
V3["「閲覧チケットを取得」 (Get viewing ticket) → present in the wallet"]
V4["paste the ViewerToken → data is displayed"]
end
F1 -->|"complete the 3 steps → 「マーケットへ進む」 (Go to the market)"| H1
H1 --> H2
H2 --> L1
L1 --> B1
B1 --> B2 --> B3
B3 --> V1
V1 --> V2 --> V3 --> V4
Step M0. Start the PWA-enabled iot-market-ui¶
What to check¶
- The PWA manifest and service worker are built into the Vite dev server
(the service worker is registered only when the page is opened over https or on localhost. It is not registered at
http://<HOST_IP>:5173, but you can still add the app to the home screen) - When opened in iPhone Safari, it can be turned into an app with
Add to Home Screen
Steps¶
Terminal D (iot-market-ui). If the iot-market-ui from Stage 5 or 6 is still running, stop it with Ctrl+C first (while 5173 is taken, Vite starts on another port):
cd ~/program/Blockchain_IoT_Marketplace
git checkout main && git pull --ff-only
Rebuild the publisher and bridge from the pulled code. Calls from iot-market-ui need the CORS support of the publisher. Then start iot-market-ui.
docker compose -f infra/docker-compose.yml --profile ssi-wallet --profile mv-bridge up --build -d
cd iot-market-ui
cat > .env.local <<EOF
VITE_RPC_URL=http://$HOST_IP:8545
VITE_PUBLISHER_URL=http://$HOST_IP:8080
EOF
npm run dev -- --host 0.0.0.0 --port 5173
Expected output¶
VITE v5.x.x ready in xxx ms
➜ Network: http://<HOST_IP>:5173/
When you open http://<HOST_IP>:5173/welcome in iPhone Safari, the 3-step
onboarding screen appears.
Step M1. Add to Home Screen (PWA install)¶
What to check¶
- "ホーム画面に追加" (Add to Home Screen) in the iOS Safari share menu creates an app icon
- When you launch the app, it runs in standalone mode without the Safari URL bar
Steps (iPhone)¶
- Open
http://<HOST_IP>:5173/in Safari - Tap the share button (a square with an upward arrow) at the bottom of the screen
- Select "ホーム画面に追加" (Add to Home Screen)
- Check the name (for example,
IW3IP) and tap "追加" (Add) - The IW3IP icon appears on the home screen → tap it to launch
Expected result¶
- An icon (the default favicon) is shown on the home screen
- When launched from the icon, the app is shown in standalone mode without a URL bar or tab bar
- Page transitions in the app work as usual (
/,/welcome,/my-data,/seller,/merchandise/[address])
On Android (Chrome)
http://<HOST_IP>:5173 is not https, so the service worker is not registered
and no install prompt appears automatically.
Add it from the menu → "ホーム画面に追加" (Add to Home screen).
Step M2. First-time onboarding /welcome¶
What to check¶
- The 3-step display guides you through preparing MetaMask + iw3ip-wallet
- "もう入っています" (Already installed) takes you to the next step
- Finally, "マーケットへ進む" (Go to the market) moves to
/
Steps (iPhone, launched from the home screen app or Safari)¶
Open http://<HOST_IP>:5173/welcome → read the three steps shown and
tap through them.
Expected display¶
STEP 1 / 3 - お財布アプリ (MetaMask) # Wallet app for payment
[MetaMask を入手する] [もう入っています →] # [Get MetaMask] [Already installed →]
STEP 2 / 3 - 閲覧チケット用アプリ (IW3IP Wallet) # App for viewing tickets
[もう入っています →] # [Already installed →]
STEP 3 / 3 - 準備完了 # Ready
[マーケットへ進む] [購入履歴を見る] # [Go to the market] [View purchase history]
Hands-on participants should already have set up both apps in Stages 1–7, so
tapping "もう入っています" (Already installed) twice takes you to STEP 3. Then tap
"マーケットへ進む" (Go to the market) to move to /.
Step M3. Purchase flow (rechecking the Stage 5/6/7 flow on mobile)¶
What to check¶
- On the existing
/merchandise/[address]page, using the MetaMask Mobile in-app browser completes the purchase and moves automatically to/purchased/[txHash] - "ウォレットで開く" (Open in wallet) is shown on
/purchased/[txHash]
Steps (iPhone, MetaMask Mobile)¶
- Set up MetaMask Mobile (first time only; the same settings as Stage 5 Step 5)
- Add a network: Network Name
Hardhat localhost, RPC URLhttp://<HOST_IP>:8545, Chain ID31337, CurrencyETH - After adding it, switch to
Hardhat localhost - Account menu → "Import private key" → enter the private key of Account #2 (noted in Stage 5 Step 1). Only an account whose PubKey is registered (Stage 6 Step E0; if you have restarted Hardhat since, redo E0) can purchase
- Add a network: Network Name
- Open MetaMask Mobile → in the built-in browser (the globe icon at the bottom right), open
http://<HOST_IP>:5173/merchandise/<Merchandise address>. Use a temperature Merchandise that you have not bought yet on the current chain (one of #0, #1 or #3; see the table in Stage 6 Step E2 for the addresses). Stage 6 Step E0 recreated the chain, so the Stage 5 purchases are gone. #3 was bought in Stage 6 Step E2. #0 or #1 cannot be used either if you re-bought it in Stage 6 Step E3 after the code expired. For example, for #0 openhttp://<HOST_IP>:5173/merchandise/0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 - (Optional) Hamburger menu → tap "Connect your Wallet" to connect MetaMask. On a phone-width screen the "Connect your wallet!" button at the top right is not shown. The button in step 3 connects automatically, so you can skip this step
- Press the "Purchase!" button and Confirm on the MetaMask side
- After a few seconds, the page moves automatically to
/purchased/<txHash>, and a QR code and the "ウォレットで開く" (Open in wallet) button are shown
This purchase history is saved in the localStorage of the MetaMask Mobile in-app browser you used.
Continue Steps M4 and M5 in this in-app browser.
Alternative using a PC browser
If operating MetaMask Mobile on the iPhone is difficult, you may open the same URL with the
MetaMask extension in Chrome on a PC and purchase there. After the purchase, the page likewise
moves to /purchased/[txHash]. However, the /my-data history is stored only on the
device used for the purchase.
Step M4. Receive the VC in iw3ip-wallet¶
What to check¶
- The deeplink on
/purchased/[txHash]launches the wallet → confirmation screen - When you approve, the PurchaseViewerVC is stored in the wallet
Steps (iPhone)¶
On /purchased/<txHash>, tap "ウォレットで開く" (Open in wallet).
iw3ip-wallet launches and shows the "IW3IP Purchase Viewer (Event-only)" confirmation screen (shown as "IW3IP 購入閲覧(Tier 1 / イベントのみ)" in a Japanese-language wallet) → approve.
The VC issuance code expires 30 minutes after the purchase claim. Receive the VC within 30 minutes of the Step M3 purchase. After it expires, the wallet fails to receive the VC (the publisher's /issuer/token returns 400 invalid_grant). The same purchase only ever gives you the same code, so, as in F of Troubleshooting in the Stage 5 hands-on, buy a temperature Merchandise you have not bought yet (one of #0, #1 or #3; see the table in Stage 6 Step E2) as in Step M3. #2 (home/event/possible_littering) also works because it has a PurchaseViewerVC presentation definition, but in Step M5 you then read event data instead of temperature data. #4 (home/event/flood_risk_high) has no PurchaseViewerVC presentation definition, so you cannot get through Step M5 with it.
Expected result¶
- A new entry in the wallet's VC list
- The claims include
merchandise_address,tx_hash,buyer_eth_addr,dataset_id - After approving, switch apps to go back to MetaMask Mobile (its in-app browser)
Step M5. History and data viewing in /my-data¶
What to check¶
- The purchase from Step M3 is stored in
localStorageand listed in/my-data - Tapping "閲覧チケットを取得" (Get viewing ticket) opens the wallet presentation screen
- After presenting, pasting the ViewerToken into the form on
/my-datashows the JSON
Steps¶
- In the MetaMask Mobile in-app browser, open
http://<HOST_IP>:5173/my-data(or use the hamburger menu → "購入履歴 / データを見る" (Purchase history / View data)) - The purchase from Step M3 is shown (dataset_id, merchandise, tx, date and time)
- Tap "閲覧チケットを取得" (Get viewing ticket) → on the page that opens, tap "ウォレットで開く" (Open in wallet) → choose the PurchaseViewerVC in the wallet and present it
- On the PC, check the token with
docker logs iw3ip-publisher 2>&1 | grep viewer_token_issued | tail -1(2>&1is needed because the publisher logs to stderr). Each publisher log line is JSON, and the token comes aftertoken=inside its"message"(the same form as in Stage 5 Step 8) - Go back to
/my-dataand tap "このデータを見る" (View this data) for that purchase to show the "ViewerToken (Bearer)" field - Paste that token into the "ViewerToken (Bearer)" field
- "取得実行" (Fetch) shows the JSON
The ViewerToken is valid for 60 seconds
Do steps 3 to 7 without a break. Send the token you checked on the PC to the iPhone with Universal Clipboard or AirDrop.
If you see viewer_token_expired, start again from step 3.
Expected JSON¶
{
"dataset_id": "home/env/temperature",
"count": ...,
"read_count": 1,
"seller_did": "unknown",
"allowed_views": [
"event"
],
"rows": [...]
}
The Merchandise you bought in Step M3 (one of #0, #1 or #3) has no seller registration, so seller_did is "unknown".
seller_did contains the seller's did:jwk:... only when you purchase a Merchandise newly
deployed and registered in Stage 7 Steps S3–S4, without recreating the publisher since then
(the seller binding lives in the publisher's memory and is lost on recreation; the Merchandise
used in Stage 7 has already been purchased and cannot be bought again).
Current limitation (to be resolved in Stage 9)
Having to paste the ViewerToken manually is the current usability issue. Completing the flow by tapping alone requires a native app with a built-in OID4VP client (method 2, Stage 9).
Completion matrix¶
| Step | What to check | Example output |
|---|---|---|
| M0 | The PWA shell works | Check manifest.webmanifest in Safari's DevTools |
| M1 | Home screen icon | IW3IP icon on the iPhone home screen |
| M2 | 3-step onboarding | "マーケットへ進む" (Go to the market) moves to / |
| M3 | Transition after purchase | QR + deeplink on /purchased/[txHash] |
| M4 | VC received in the wallet | Claims include merchandise/tx/eth |
| M5 | History shown and data fetched in /my-data |
JSON containing dataset_id and rows |
Troubleshooting¶
A. Add to Home Screen does not appear as an option¶
Cause: You are using a browser other than Safari, or fetching the manifest failed.
Fix:
- Confirm that you opened the page in Safari (the iOS default)
- Open
http://<HOST_IP>:5173/manifest.webmanifestdirectly and check that JSON is displayed - Confirm that you opened the page with the LAN IP, not
http://localhost
B. The app launches from the icon but the browser bar is shown¶
Cause: display: "standalone" in the manifest is not applied, or
Safari's cache.
Fix: Long-press the home screen icon to delete it → add it again in Safari.
C. Tapping "ウォレットで開く" (Open in wallet) does not launch the wallet¶
Cause: The openid-credential-offer:// scheme is not registered by the wallet.
Fix:
- Check that iw3ip-wallet is already running
- Check troubleshooting item C of Stage 5 (wallet cache, Metro bundler)
D. The history in /my-data is empty¶
Cause: One of the following.
- Writing to
localStorageon/purchased/[txHash]failed at purchase time (private browsing mode, for example) - The publisher is old and lacks CORS support, so
/marketplace/claimfrom/purchased/[txHash]failed (the history is saved only when the claim succeeds)
Fix:
- Turn off private browsing in Safari
- After
git pull, rebuild the publisher withcd ~/program/Blockchain_IoT_Marketplace && docker compose -f infra/docker-compose.yml --profile ssi-wallet --profile mv-bridge up --build -d - Make another purchase and check
/my-dataagain
E. Other¶
See also Stage 5 troubleshooting and the troubleshooting section of Stage 7.
Limitations (to be resolved in Stage 9)¶
- Pasting the ViewerToken: Automatic retrieval requires an implementation on the wallet side that calls the publisher API (method 2 = Stage 9)
- Switching between apps: You move back and forth between three apps (PWA / MetaMask / iw3ip-wallet). Completing everything in one app is method 2
- Offline support: It is a PWA, but the service worker is pass-through. Chain reads are always online
- iOS notifications / background processing: Limited by the iOS PWA restrictions
Next steps¶
Next is Tier the response by trust (DataUserVC / Stage T) in 2.5. You change what is shown according to the recipient's trust level.
- Stage T calls
/marketplace/claimdirectly with curl, so it does not use the Hardhat node, the bridge or iot-market-ui. You can stop them. - The publisher is restarted in §1 of Stage T.
- Stage T also uses the phone wallet (iw3ip-wallet).