React Moralis
An npm Package with Custom React Hooks for Moralis SDK Features.
This project is a thin React wrapper around Moralis, to easily call SDK functions and display data.

Quick Start

Make sure to have react, react-dom and moralis installed as dependencies. Then install react-moralis:
1
npm install react-moralis
Copied!
or:
1
yarn add react-moralis
Copied!
Then wrap your app in a <MoralisProvider>:
1
import React from "react";
2
import ReactDOM from "react-dom";
3
import { MoralisProvider } from "react-moralis";
4
​
5
ReactDOM.render(
6
<MoralisProvider appId="xxxxxxxx" serverUrl="xxxxxxxx">
7
<App />
8
</MoralisProvider>,
9
document.getElementById("root"),
10
);
Copied!
And call the hooks inside your app:
1
import React from "react";
2
import { useMoralis } from "react-moralis";
3
​
4
function App() {
5
const { authenticate, isAuthenticated, user } = useMoralis();
6
​
7
if (!isAuthenticated) {
8
return (
9
<div>
10
<button onClick={() => authenticate()}>Authenticate</button>
11
</div>
12
);
13
}
14
​
15
return (
16
<div>
17
<h1>Welcome {user.get("username")}</h1>
18
</div>
19
);
20
}
Copied!

GitHub

For more info see the extended documentation at the GitHub repo.
​
Last modified 3mo ago
Copy link