diff --git a/README.md b/README.md index 035a8efccbcc6a0609580711953b0f6c64812b63..bff397f464501f0402e627483b13afcdc1955ef1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ - [What modified and why](#what-modified-and-why) - [Known issues](#known-issues) - [Address format](#address-format) + - [Asset-gating](#asset-gating) ## README for xx Network @@ -11,19 +12,16 @@ (See [KSM_README.md](./KSM_README.md) for upstream README document.) What it is: -- Make access to your site or "gated" part of your site possible only to users with a certain amount of xx coins in their Polkadot{.js} (not .{js} - I made a typo in the screenshot) wallet -- You an also read wallet name - I have it `123123123` in the screenshot, but it'd normally be "Joe Mc Coin" or something more useful -- You can set that balance to any amount (10, 100, 100,000 XX) or mandate different balances for different paths on your Web site -- Works with static and dynamic Web pages +- Make access to your site "gated" only to users with a certain amount of xx coin or a xx Network asset in their Web3 wallet (works with Polkadot{.js}) + - You can set that balance to any amount (10, 100, 100,000 XX) or mandate different balances for different paths on your Web site + - Works with static and dynamic Web pages + - Both token- and "asset"-gating works. The check for (xx Network) asset kind and balance is currently CLI only (see in Known issues at the bottom).  Thank you to [the original author](https://polkadot.study/tutorials/tokengated-polkadot-next-js/intro) and the guy who [forked it](https://github.com/yk909/polkadot-js-tokengated-website/) to apply some fixes (verify/compare if you plan to use in production, of course). -What it is not (yet): -- "Asset"-gating - there's no way to evaluate address balance for (xx Network) assets held. [This post](https://armchairancap.github.io/blog/2023/11/05/xx-network-asset-gated-access) has code samples that can be used to achieve that - -This sort of works now and I'm sharing in the hope someone will use it for xx Network or other Substrate projects/chains for which the upstream forks don't provide instructions. +I'm sharing in the hope someone will use it for xx Network or other Substrate projects/chains for which the upstream forks don't provide instructions. ## How to run @@ -49,11 +47,11 @@ RPC_ENDPOINT=ws://192.168.1.30:63007 Go to http://localhost:3000 in the browser in which you installed Polkadot{.js} and connect the extension to http://localhost:3000, generate an address and make it restricted for use on xx Network (I hoped this would ensure balance will be looked up correctly, but it was not). -With that, I can login (see [xx_screenshot.png](./xx_screenshot.png) and balance of xx coins is correctly shown (since v1.1). We could probably check for assets/tokens issued on xx Network as well, but I haven't looked into that yet. +With that, I can login (see [xx_screenshot.png](./xx_screenshot.png) and balance of xx coins is correctly shown (since v1.1)). -(Note that, if you go to https://wallet.xx.network, Polkadot{.js} can let you add the wallet from the browser extension and show it in xx Network Wallet. Neat!) +(Note that, if you go to https://wallet.xx.network, Polkadot{.js} lets you add the wallet from the browser extension and show it in xx Network Wallet. Neat!) -`npm run build` builds okay, but has warnings about multiple versions of some package, etc. I don't know JS well enough to fix this quickly. +`npm run build` builds okay, but has a fake warning about multiple versions of some package. ## Use cases @@ -115,3 +113,26 @@ The FAQs say [it's normal to see another address](https://polkadot.js.org/docs/k You can configure the wallet to default to xx Network, by the way (see the screenshot), to avoid that. +### Asset-gating + +Currently it works only in the console and it may be xx Network-specific (e.g. it seems Polkadot doesn't use Assets, so if you want to reuse this with another coin maybe check if it supports assets). + +In the code we check the balance of asset ID 5 (which on xx Network happens to be `JUNK`) and warn if it's less than 2. I have 1 on mine, which triggers a warning like so. + +```raw +ksmAddress: 6aCE19CakDJBp8wnVHB2HpHYfaeNiwx2RxQcsAcyWvPLVn5k +Wallet address on xx Network: 6aCE19CakDJBp8wnVHB2HpHYfaeNiwx2RxQcsAcyWvPLVn5k +Wallet balance on xx Network: 1840527453 +Account balance for asset 5 and address 6aCE19CakDJBp8wnVHB2HpHYfaeNiwx2RxQcsAcyWvPLVn5k: 1 +Warning: Account balance for asset 5 is less than 2. +token { + name: 'the-dude', + sub: '5GxeeFALkRvjnNgkiMjiP6q2GGnZ1ZmFyjCusHG4VoezqZSN', + freeBalance: '0x0000000000000000000000006db4385d', + iat: 1730995852, + exp: 1733587852, + jti: 'c7a8e87a-0bff-46da-a5be-ffc51726d6dc' +} +``` + +Showing this information in the UI is a TODO item. You may find more on asset-checking ideas [here](https://armchairancap.github.io/blog/2023/11/05/xx-network-asset-gated-access).