I am creating a React.js DApp which will interact with Rootstock (RSK) deployed smart contracts. Recently I came across a React library called useDApp. This library automates the blockchain connection, smart contract interaction and sending transactions by using React hooks and context providers. For example:
const { activateBrowserWallet, account } = useEthers();
const etherBalance = useEtherBalance(account);
However, I don't see Rootstock among the supported networks.
I have tried to create a Rootstock configuration as described in the docs:
const config = {
readOnlyChainId: 30,
readOnlyUrls: {
31: 'https://public-node.testnet.rsk.co',
30: 'https://public-node.rsk.co',
},
};
Unfortunately, adding the above appears to be insufficient, and I was unable to connect to either RSK Mainnet nor RSK Testnet.
Is it possible to configure useDApp to connect to Rootstock?
Yes connecting useDApp to Rootstock is possible.
(1) Create config objects for both networks (Rootstock Testnet, Rootstock Mainnet).
(2) Specify Multicall smart contract addresses, within these config objects.
They should look like this:
(3) Create useDApp configuration using these network configs:
(4) Connect the useDApp configuration to
DAppProvider(e.g. inindex.js)(5) Now you are ready to go with the blockchain data in your React components: