Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


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

    Thomas GrecoThomas Greco

    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



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.