This project demonstrates a gaming use-case using the pallet-rent pallet.
This project uses the foundations from the following projects:
This project showcases the ability to create, rent out, rent, destroy, and equip items onto a "character" using the pallet-rent pallet.
Communication with the pallet-rent
pallet is done by using the substrate-front-end-template
modules which provide easy-to-use interfaces to connect with Substrate nodes and your Polkadot wallet.
The project requires Yarn to be installed.
To get started, clone the repository and install the dependencies:
Copy code
git clone https://github.com/ok-Alice/nft-on-rent-ui.git
cd nft-on-rent-ui
yarn install
yarn start
yarn build
and open build/index.html
in your favorite browser.
Build container:
docker build -t pallet-rent-character-loadout -f .docker/Dockerfile .
Run container exposing its port 80 to local port 8000 (change to your liking)
docker run -d -p 8000:80 pallet-rent-character-loadout
The template's configuration is stored in the src/config
directory, with
common.json
being loaded first, then the environment-specific json file,
and finally environment variables, with precedence.
development.json
affects the development environmenttest.json
affects the test environment, triggered inyarn test
command.production.json
affects the production environment, triggered inyarn build
command.
Some environment variables are read and integrated in the template config
object,
including:
REACT_APP_PROVIDER_SOCKET
overridingconfig[PROVIDER_SOCKET]
More on React environment variables.
When writing and deploying your own front end, you should configure:
PROVIDER_SOCKET
insrc/config/production.json
pointing to your own deployed node.
There are two ways to specify it:
- With
PROVIDER_SOCKET
in{common, development, production}.json
. - With
rpc=<ws or wss connection>
query parameter after the URL. This overrides the above setting.
The custom hook useSubstrate()
provides access to the Polkadot js API and thus the
keyring and the blockchain itself. Specifically it exposes this API.
{
setCurrentAccount: func(acct) {...}
state: {
socket,
keyring,
keyringState,
api,
apiState,
currentAccount
}
}
socket
- The remote provider socket it is connecting to.keyring
- A keyring of accounts available to the user.keyringState
- One of"READY"
or"ERROR"
states.keyring
is valid only whenkeyringState === "READY"
.api
- The remote api to the connected node.apiState
- One of"CONNECTING"
,"READY"
, or"ERROR"
states.api
is valid only whenapiState === "READY"
.currentAccount
- The current selected account pair in the application context.setCurrentAccount
- Function to update thecurrentAccount
value in the application context.
If you are only interested in reading the state
, there is a shorthand useSubstrateState()
just to retrieve the state.
The Account Selector provides the user with a unified way to select their account from a keyring. If the Balances module is installed in the runtime, it also displays the user's token balance. It is included in the template already.
This project was created by Kenneth Verbeure.
This project is licensed under the MIT License.