Skip to main content

Auth Example - Connect to GDN

The first step in using GDN is to establish a connection to a local region. When this code executes, it initializes the server connection to the region URL you specified.

The code example below shows how you might use authentication in your code.

note

The example below assumes you have already installed one or more Macrometa SDKs. For instructions, refer to Install SDKs.

const jsc8 = require("jsc8");

// Email and password to authenticate client instance
const email = "nemo@nautilus.com";
const password = "xxxxxx";
const fabric = "_system";

const client = new jsc8({
url: "https://play.paas.macrometa.io",
fabricName: fabric
});

// Or create an authenticated instance with a JWT token.
const clientUsingJwt = new jsc8({
url: "https://play.paas.macrometa.io",
token: "XXXX",
fabricName: fabric
});

// Or create an authenticated instance with an API key.
const clientUsingApiKey = new jsc8({
url: "https://play.paas.macrometa.io",
apiKey: "XXXX",
fabricName: fabric
});

async function main() {
await client
.login(email, password)
.then((e) => console.log("1. User authentication done!"))
.catch((error) => error);
}

main()
.then()
.catch((error) => console.log(error));