npx create-next-appat the command line to create a base React project, which is a very simple minimalist structure for a web application, then we need to install some dependencies related to the DApp.
web3-reactis a web3 upper layer wrapper library for the React API, it helps us to call the RPC API in a simpler way, very useful type hints are also provided.
Explanation of web3 and the libraries associated with it:The imToken environment does not provide you with a built-in
ethersjslibrary, only a basic provider, you just need to install your favorite class library in your project and inject the provider from imToken into it.
Providerso that we can call the RPC API using Hooks in each component, add the Provider Component (which is actually a
React Context) to the root component of the React project, and add a method to get the Provider in the imToken environment:
activatemethod to start trying to connect, if the connection fails we can get an error message from the host environment, if the user completes the authorization, then the
accountwill be updated.
text message, and if we succeed, we will get the signature result.
active. Once the connection is confirmed, we can use
signMessageto request the user to authorize the signature operation.
https://token-example-react.vercel.app/directly in imToken App, here is the online link to the sample project, you can see how it works by previewing the link.