Add Authentication for Fortmatic's Ethereum Wallet to a React Application

Thomas Greco
InstructorThomas Greco
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

This lesson is meant to be an introduction to using the Web3 API inside of a React Application. By the end, you'll have learned how to hook up communication between an user's Fortmatic's Wallet and the Ethereum's Rinkeby Test Network.

External Resources

Thomas Greco: [0:01] Above our wallet component, I'm just going to create this initializeFortmatic function. In here, I'm just going to create this fm variable and set it equal to our Fortmatic constructor that we've imported above. It's important to note that I'm passing in my API key here. Otherwise, this isn't going to work.

[0:24] This fm constant will allow us to interact with the wallet that Fortmatic provides us with. Then from here, use Fortmatic's getProvider method to inform web3 of which Ethereum blockchain to connect to. By default, Fortmatic is going to hook us up to the Rinkeby testnet.

[0:58] Once we have that locked up, we could use web3.eth module, and thus all of these methods it provides us with, but we're just going to say getAccounts. getAccounts is going to return a promise. We're going to chain an event on it, and then we're just going to log the response of this promise.

[1:27] Before we could do that, we need to use the useEffect hook inside here, and then we're only going to want this to fire once the component mounts. Therefore, we're going to use an empty dependency array.

[1:44] Fortmatic is already picking up my credentials because I've already logged in, so I'm just going to quickly kill my server. If I fire it back up and I try to visit our application, we'll see that Fortmatic's dialogue is, in fact, showing up for us. It already has my email ready for me, and I'll pass the password in. It's going to give me a nice little welcome back sign.

[2:15] More importantly, it's going to log our wallet address just like we set it up to.

egghead
egghead
~ 19 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today