git.delta.rocks / unique-network / refs/commits / 0a49946aa7b2

difftreelog

source

doc/hackusama_walk_through.md12.3 KiBsourcehistory
1# Hackusama Walk-Through Demo23This document walks through all Hackusama deliverables made in relation to NFT Blockchain submission.45## Updates to NFT Parachain67[Project Description](https://github.com/usetech-llc/nft_unity/blob/master/README.md)89### Deployed NFT TestNet1011The TestNet public node is avaiable at wss://unique.usetech.com. It is easy to verify that it functions with the12standard AppsUI:13141. Open the [Apps UI](https://polkadot.js.org/apps/#)152. Click on the network icon in the top left corner163. Scroll down the list and input `wss://unique.usetech.com` under "custom endpoint"174. After connection is established, copy these18   [UI Custom Types](https://github.com/usetech-llc/nft_parachain#ui-custom-types) and paste them in19   [Developer Settings](https://polkadot.js.org/apps/#/settings/developer). Hit "Save" button.205. Now the NFT node is connected with AppsUI.216. Go to [Chain State](https://polkadot.js.org/apps/#/chainstate) and verify that NFT pallet is visible and you can read22   information from it.237. For example, select nft -> collection, and enter collection ID 4 (for SubstraPunks) and click "+" button. You will24   see the collection properties such as UTF-16 encoded collection name and description, UTF-8 encoded token prefix, the25   size of custom data, etc.2627#### Getting some Unique Tokens28291. Install Polkadot{.js} extension if you don't have it already installed. Here are the links for30   [Chrome](https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd) and31   [Firefox](https://addons.mozilla.org/en-US/firefox/addon/polkadot-js-extension/) extensions.322. Create an address333. Contact us at [Unique Network Telegram channel](https://t.me/joinchat/DPVt1RwN50Uic_Q9lFcg9A) in order to get some34   Unique token and some Re-Fungible tokens. Faucet is comming soon, we will update this instructions when it goes live.3536### Smart Contracts Pallet37381. Open [Contracts](https://polkadot.js.org/apps/#/contracts) tab. It only appears in the UI when Smart Contracts pallet39   is included in the runtime.402. Additionally, we can find an existing smart contract. Click on "Add an existing contract" link.413. Input this contract address: `5GdNqKMv4Sszq3SRd3TkXNa6a9ct4D3nXvtTWTFR7rTyccVJ`424. Input any contract name, for example `Claim Substrapunks`435. Download and drag-and-drop this44   [metadata.json](https://github.com/usetech-llc/substrapunks/releases/download/v1.0.2/metadata.json) file into45   contract ABI field.466. Click Save. The contract appears in the page. If the contract did not exist at that address, the UI would display an47   error message: "Unable to find deployed contract code at the specified address".4849### Integration Between Smart Contracts and NFT Pallet5051This was one of the most challenging parts of the Hackusama for us. The pre-RC4 versions of Substrate did not function52properly when we tried to use `ext_dispatch_call` to dispatch a runtime call to NFT pallet from Contracts pallet, and53RC4 had the `ext_dispatch_call` already removed to "free space" for some friendlier way of interaction between pallets,54that was not yet implemented. Thanks to Alexander Theißen who reverted the removal of `ext_dispatch_call` and created a55special branch based on RC4 for us!5657The smart contract source code exists in this58[repository folder](https://github.com/usetech-llc/nft_parachain/tree/master/smart_contract/ink-types-node-runtime), but59the best way to test how the interaction between smart contracts and NFT pallet works is to see it in action using the60[SubstraPunks Game Example](https://ipfs-gateway.usetech.com/ipns/QmaMtDqE9nhMX9RQLTpaCboqg7bqkb6Gi67iCKMe8NDpCE/) that61uses smart contract to claim free characters. The complete demo of this game will come later, so please bare with us and62let's put this item demonstration for a bit later.6364### Re-Fungibility support6566This feature is best demonstrated in action using our NFT wallet. First, you need to have some Unique and Re-Fungible67tokens. [This section](#getting-some-unique-tokens) tells how to get them.68691. Open the [NFT Wallet](https://uniqueapps.usetech.com/#/nft)702. Search for collection called "Artwork". Search can be done either by collection name or collection ID (which is 2).713. Click on "+ Add collection" in search results. The collection will appear under "My collections"724. Expand the "Artwork" collection and see that you own a token with a partial balance735. Transfer the token to some other address: Click "Transfer token" and enter address and the amount. Amount should be74   entered as decimal fraction. For example "0.01" to transfer 1/100th part of the token.756. Observe that your balance decreased by the amount you entered.7677#### The Hard Way7879Also, the Re-Fungible support can be demonstrated using the standard UI features without NFT wallet.80811. Open [Chain State](https://uniqueapps.usetech.com/#/chainstate).822. Select "nft" - "reFungbleItemList"833. Enter parameters: 2 and 1, click "+" button844. Observe the following data structure returned:8586```87{88  Collection: 2,89  Owner: [90    {91      owner: 5FNujvbtMyKoJC2zTrfGVaQek7jhfR1L558BMhogfFfD7veH,92      fraction: 3,00093    },94    {95      owner: 5D73wtH5pqN99auP4b6KQRQAbketaSj4StkBJxACPBUAUdiq,96      fraction: 3,00097    },98    {99      owner: 5FZeTmbZQZsJcyEevjGVK1HHkcKfWBYxWpbgEffQ2M1SqAnP,100      fraction: 2,000101    },102    {103      owner: 5EnzEXBuxFHdymceAAtstym8FETQqH4inx29XJSP6uHaCUiP,104      fraction: 1,000105    },106    {107      owner: 5GU6iHnc3qTMaufmKYzHUpDmVN2CgzA2JMcGFQLcKNDbE7c6,108      fraction: 1,000109    }110  ],111  Data:112}113```114115The Owner field contains a list of owners with the fractions they own. The fractions are represented as fixed point116decimals. The number of decimal points in this fraction is determined by collection properties. For example, in the117Artwork collection this property is equal to 4. The owned fraction is then determined as `fraction` divided by11810^DecimalPoints, i.e. 10,000 in this case.1191205. Staying in Chain State, select "nft" - "colection"1216. Input "2" and click "+"1227. Observe the following structure returned. It tells that collection is ReFungible and DecimalPoints field is equal123   to 4.124125```126{127  Owner: 5FNujvbtMyKoJC2zTrfGVaQek7jhfR1L558BMhogfFfD7veH,128  Mode: {129    ReFungible: [130      0,131      4132    ]133  },134  Access: 0,135  DecimalPoints: 4,136  Name: [137...138```139140### Off-Chain Schema to store token image URLs141142This feature is best demonstrated in action using our NFT wallet. First, you need to have some Unique and Re-Fungible143tokens. [This section](#getting-some-unique-tokens) tells how to get them.1441451. Open the [NFT Wallet](https://uniqueapps.usetech.com/#/nft)1462. Search for collection called "Artwork". Search can be done either by collection name or collection ID (which is 2).1473. Expand "Artwork" collection1484. Click on the image to zoom in.1495. Right-click on the image and select "Open Image in New Tab"1506. Note the image URL:151152```153https://ipfs-gateway.usetech.com/ipfs/QmUSv64cUmL2m44QYkUFWmH89qykC8VLPFwjhpeAScjejS/image1.jpg154```1551567. Open [Chain State](https://uniqueapps.usetech.com/#/chainstate).1578. Select "nft" - "colection"1589. Input "2" and click "+"15910. Scroll down:160161```162  ],163  TokenPrefix: ARTu0000,164  CustomDataSize: 0,165  OffchainSchema: https://ipfs-gateway.usetech.com/ipfs/QmUSv64cUmL2m44QYkUFWmH89qykC8VLPFwjhpeAScjejS/image{id}.jpg,166  Sponsor: 5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM,167  UnconfirmedSponsor: 5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM168}169```17017111. Observe the field called `OffchainSchema`. This field defines the URL schema that is used to contruct token URLs172    based on the token ID. In this particular example, the {id} template variable is replaced with token id 1, which173    results in the proper image URL.174175### New economic models176177This feature is best demonstrated when you own a SubstraPunk character. Please proceed with the demonstration, and then178come back after you claim one.1791801. Create a new address in Polkadot{.js} extension. We need an address that has zero balance in Unique tokens. Let's181   call it "ZERO BALANCE" address.1822. Open the [NFT Wallet](https://uniqueapps.usetech.com/#/nft)1833. Search for collection called "SubstraPunks" (partial search also works, so you can just type "punk" and hit Enter)1844. Add collection1855. Expand substrapunks collection and transfer your PNK token to your "ZERO BALANCE" address.1866. Now select your "ZERO BALANCE" address in the drop-down list and repeat searching and adding the collection for this187   address.1887. Transfer token back to your main address. Observe that despite the zero balance, the transfer is successful.189190### Allow Lists and Public Mint Permission191192We did not complete these features in time by Hackusama deadline, but because they are important for security of the193network, we completed them after the deadline anyway. They can be seen in branch194[feature/allow_list](https://github.com/usetech-llc/nft_parachain/tree/feature/allow_list). Here are the permalinks to195essential functions:196197[allow_lists](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L659)198199[mint_permission](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L373)200201## NFT Wallet202203[Project Description](https://github.com/usetech-llc/apps/blob/master/README.md)204205All features of the NFT Wallet were already demonstrated previously:206207-   Enables adding favorite collections208-   Shows tokens owned209-   Allows NFT and Re-Fungible transfers210-   Shows Re-Fungible Balances211-   Shows Token Images212213## Our version of AppsUI214215The UI was also mainly demonstrated. We only need to show some configuration that happens behind the scenes:216217### Loads appropriate custom API types2182191. Open the [NFT Wallet Developer Settings](https://uniqueapps.usetech.com/#/settings/developer)2202. Observe that Custom UI types are already in place221222### Defaults to NFT TestNet2232241. Open the [NFT Wallet](https://uniqueapps.usetech.com/)2252. Observe that Unique Network icon appears in the left top corner without a need to specify the network2263. Click on Unique Network icon and see that `NFT Testnet` is in the network list227228## Unity API and SDK PoC229230[Project Description](https://github.com/usetech-llc/nft_unity/blob/master/README.md)231232In order to see Unity Asset in action, please follow the instructions in this README file:233234[Demonstration](https://github.com/usetech-llc/nft_unity/blob/master/src/DemoApplication/readme.md)235236## SubstraPunks Game237238[Project Description](https://github.com/usetech-llc/substrapunks/blob/master/README.md)239240First, you will need some Unique balance. [This section](#getting-some-unique-tokens) tells how to get the TestNet241currency.2422431. Open this [SubstraPunks Game](https://ipfs-gateway.usetech.com/ipns/QmaMtDqE9nhMX9RQLTpaCboqg7bqkb6Gi67iCKMe8NDpCE/)244   IPFS link2452. Find a character you like that still has red background. Red indicates that the character was not yet claimed by246   anyone.2473. Allow access for Polkadot{.js} to this site2484. Click "Claim" button2495. Select the account that has some Unique balance2506. Click "Claim" again, sign transaction, and wait until it mines.251252Let's make a pause here: You were just demonstrated how the integration between smart contracts and NFT Pallet works.253This is what we've been previously talking about [here](#integration-between-smart-contracts-and-nft-pallet)254255The source code of the generic smart contract is located in256[smart_contract](https://github.com/usetech-llc/nft_parachain/tree/dev/smart_contract/ink-types-node-runtime) folder.257But to demonstrate smart contracts in practice we created additional258[Claim Contract](https://github.com/usetech-llc/substrapunks/tree/master/smart_contract) to implement claiming259functionality in this game.260261Here is how Claiming works: Claim Contract owns all characters in the game initially. Player sends a transaction calling262the method claim:263264```265fn claim(&mut self, collection_id: u64, item_id: u64, new_owner: AccountId)266```267268Inside the method `claim` there is a call made to NFT pallet to transfer the token that is being claimed to the player:269270```271runtime_calls::transfer(collection_id, item_id, new_owner);272```2732747. Follow the link to [NFT Wallet](https://uniqueapps.usetech.com/#/nft)2758. Search for "SubstraPunks" collection, add it2769. Expand the collection and find your character in there!27710. Now you can try transfers and test the [economic model](#new-economic-models), the last thing we put off until a278    SubstraPunks character is claimed.