Auth with 3Box

Ryan Pedersen
1 min readSep 4, 2019

--

Simple walkthrough describing the code needed to authenticate with 3Box.

web3 actions 🦊

On line 3, window.ethereum.enable() requests access to user accounts from MetaMask or another DApp browser. The window.ethereum piece is the Ethereum provider that is injected — in this case, it is MetaMask. It kicks off the process and is used as the ethereumProvider param in the openBox() function on line 7. The ethereum.enable() piece allows app providers to request access to the user account, returning a Promise.

More info in the MetaMask documentation:

3Box actions 🖋

Box.openBox() takes the user's ethAddress and authenticates to their associated 3Box.

Once authenticated into 3Box, use that variable to authenticate into a selected space with box.openSpace(), passing in the space name as a string.

Any time openBox() is called, onSyncDone() should be called. openBox() sets a callback function to let you know when the 3Box DB is fully synced.

Full 3Box documentation:

Conclusion 💭

That’s it! We’ve gone through web3, 3Box, and 3Box space authentication with just that code.

--

--