yarn
or npm i
If you want to use ESLint and Prettier while developing just copy sample settings inside
sample-eslint.txt
and sample-prettier.txt
then create these two files:
However, if you want to opt out in using these, just uninstall the Dev Dependencies:
An Infura ID is needed for Wallet Connect.
As of now, these are the reusable components in this scaffolding:
<Connector />
<Crementor />
<Message />
<NiceButton />
<Collapsible />
Jump to bottom section to read more about these components.
As of now, these are the custom hooks available:
useSignature
Jump to bottom section to read more about these components.
The EthersProvider is the main component. It will return instances of 'ether' and 'web3Modal', and its own ethersProvider util data. Purpose is to just pull the instances instead of always importing it. These are all the data that EthersProvider can return:
Also, the EthersProvider has a askOnLoad
props. If it is set to true
(its default state), on site's load it will trigger the Metamask to prompt asking the user to switch to Ethereum network. Setting it to false
will prevent it from prompting. Check sample usage below.
There are two (2) main scenarios to implement initialization.
SCENARIO A1: You want to manually handle everything:
SCENARIO A2: Still scenario A, but this is a shorter version:
The ethersProvider util inside scenario A2 will handle all initialization and errors.
SCENARIO B: You have multiple components, and you want the Navigation component to handle the initialization and the rest of the other components can access the data, e.g., Body component can access all of it.
What is happening is that the <Navigation />
component which contains the <Connector />
component handles all connection and disconnection. So your <Body />
component will become a receiver only and can still access all data through the EthersProvider context, based on the code above.
The MessageNet is somehow also acts as a provider. Instead of importing the <Message />
reusable component and use it for notifications, errors, etc., we will just encapsulate all components that need to spit out some UI messages. See example below:
You can find these inside src/components
directory. Though opinionated, I would highly suggest we do it like this. Just to stay a bit organized.
core
โ> Will contain all utility components, like the one that handles connections, processes data, etc.
pages
โ> Are simply for pages and layouts. If it's only a landing page, you can still call it Home
. Then inside it you can put all layouts pertaining to <Home />
.
ui
โ> Will contain all reusable UI components. Check next section.
useSignature
This custom hooks allows to quickly sign a message using a provider, for example, Metamask. You just pass a message you wanna sign and then gets all the data back. See example:
The signMessage
function takes 2 arguments, message
and signer
. The message
is required but the signer
is optional since this boilerplate is already encapsulated inside EthersProvider
component.
<Connector />
This core component is responsible for connecting and disconnecting the user. Below are the props and default props for this component:
forceSwitch
is useful when you want to trigger network change after the connecting process. Especially, if askOnLoad is set to false in <EthersProvider askOnLoad={false} />
. Default network or chain is '0x1' which is the Ethereum network.
<NiceButton />
This is a customizable and reusable button component. This can work as a link, a button with an icon, or just a simple button. Below are the props and default props for this component:
Here is a sample usage of this component using it as a button with an icon:
Recommended icon package to use is: https://react-icons.github.io/react-icons/. If the link props is present it will automatically be converted to link-type button.
<Crementor />
This reusable component is used when increment and decrement functions are needed. Below are the props and default props of this component:
And, here is the sample usage of this component:
TODO - continueโฆ