If you haven't already, make sure to visit the Getting Started guide. You'll need an API Key going forward.
Install from NPM:
$ npm i simpleid-node-sdk
Once you've installed the package import the library:
const SimpleID = require('simpleid-node-sdk');
From there, you'll want to create an instance of SimpleID with your configuration options:
const simple = new SimpleID({appOrigin: "https://www.simpleid.xyz",scopes: ['store_write', 'publish_data'],apiKey: "123-fake-api-key-456",appName: "SimpleID",network: "ropsten",localRPCServer: 'http://localhost:7545'});
Parameter | Purpose |
appOrigin | This is your verifiable application origin url |
scopes | For Blockstack, you must define the scopes you'd like to use.
|
apiKey | Your SimpleID API Key |
network | The ethereum network you'd like to use. Choices are: |
localRPCServer | If you're running a local Ethereum node or testing with Ganache, you can point SimpleID to the |
Now that SimpleID has been initialized, you can start using it. Let's start by authenticating a user. SimpleID is passwordless, so you do not need to specify whether a user is signing up or signing in. We take care of that for you. You will ultimately need to call the authenticate function twice: once with just the user's email address and once with the email + authentication token we send the user.
const payload = { email: userEmail};const signup = await simple.authenticate(payload);
This will take the user's email address, check if the user is an existing user or a new user, and then send a one-time token. If the user is new, SimpleID will generate blockchain wallets, generate application specific encryption keys.
The user will receive the one-time token via email and will need to supply that to your application in some way. When you have that token, you can call the authenticate function again like this:
const payload = { email: userEmail, token: authToken };const signup = await simple.authenticate(payload);
That's all there is to it. You're user will be signed in and ready to store data, interact with smart contracts, buy cryptocurrency, and broadcast transactions.
Let's move on to Ethereum-specifc functionality.