1. Install 3Box SDK

Integrate 3Box into your web project

First, install the 3Box package.

Install 3Box in your npm project:

$ npm install 3box

Then, import the 3Box module.

Import 3Box into your project using one of the following methods:

Import the 3box module:

const Box = require('3box')

Import using the dist build in your html code:

<script type="text/javascript" src="../dist/3box.js"></script>

Load a remote copy from unpkg CDN

<!-- The most recent version -->
<script src="https://unpkg.com/3box/dist/3box.js"></script>
<!-- The most recent minified version -->
<script src="https://unpkg.com/3box/dist/3box.min.js"></script>
<!-- Load specific versions by specifying the version as follows -->
<script src="https://unpkg.com/[email protected]<version>/dist/3box.js"></script>

More Build Options

Optimize build for read-only 3Box API

If you only want to fetch profile data from 3Box's profile APIs you can optimize by importing only those functions or the API specific dist file. Since this includes minimal dependencies, file size is ~ 80kb vs 4+mb for the full build.

const {
profileGraphQL, getProfile,
getProfiles, getVerifiedAccounts
} = require('3box/lib/api')
<script src="https://unpkg.com/3box/dist/3box.api.min.js"></script>

Resolving build size issues and out of memory errors

Some platforms, tooling, or configs have caused the build process to throw out of memory errors. This is a combination of the size of our library (plus dependencies) and the specific configs you have for your build. It could be things like tooling running on dependencies and not just your source or dependencies be recursively resolved. You can attempt to build the library anyways by adding the follow environment variable to increase memory for the node process.

NODE_OPTIONS=--max_old_space_size=4096 npm run build