A TypeScript SDK for the Gateway API. This library is built with TypeScript developers in mind, but it also works with JavaScript.
Note: Our latest version of sdk works without adding any extra configuration for frontend environments.
- Full type information for methods and responses.
- Bearer Token Support
- Supports Node.js 18+.
- Works in frontend environments without adding any extra configuration.
npm install @gateway-dao/sdk
pnpm add @gateway-dao/sdk
yarn add @gateway-dao/sdk
To setup the gateway client we will authenticate with a bearer-token,api key and wallet private key as follows
import { Gateway } from '@gateway-dao/sdk';
const gateway = new Gateway({
apiKey: 'your-api-key',
token: 'your-token',
url: 'https://sandbox.protocol.mygateway.xyz/graphql',
walletPrivateKey: 'your-private-key', // store this in env file!
});
The wallet private key is not send anywhere and is just used to sign messages on behalf of developer/organization using it. This way we minimize signature errors on protocol and provide smoother developer experience
Make sure you add token without Bearer as we add Bearer automatically when you make request. Else it will give you Unauthorized error even if your token is correct For example
import { Gateway } from '@gateway-dao/sdk';
const gateway = new Gateway({
apiKey: 'your-api-key',
token: 'Bearer your-token',
// wrong will not work just use token: 'your-token'
url: 'https://sandbox.protocol.mygateway.xyz/graphql',
walletPrivateKey: 'your-private-key', // store this in env file!
});
This library supports Bearer Token along with Api Key. Do not share your authentication token with people you don’t trust. This gives the user control over your account and they will be able to manage PDAs (and more) with it. Use environment variables to keep it safe.
Make sure to add try catch blocks around methods to catch all the validation and protocol based errors.
import { Gateway, UserIdentifierType } from '@gateway-dao/sdk';
const gateway = new Gateway({
apiKey: 'your-api-key',
token: 'your-token',
url: 'https://sandbox.protocol.mygateway.xyz/graphql',
walletPrivateKey: 'your-private-key', // store this in env file!
});
async function main() {
try {
let obj = {
dataModelId: 'uuid-here',
description: 'test',
title: 'test',
claim: {
gatewayUse: 'test',
},
owner: {
type: UserIdentifierType.GATEWAY_ID,
value: 'test',
},
};
const { createPDA } = await gateway.pda.createPDA(obj);
} catch (error) {
console.log(error); // Can log it for degugging
}
}
main();
import { Gateway } from '@gateway-dao/sdk';
const gateway = new Gateway({
apiKey: 'your-api-key',
token: 'your-token',
url: 'https://sandbox.protocol.mygateway.xyz/graphql',
walletPrivateKey: 'your-private-key', // store this in env file!
});
async function main() {
try {
let obj = {
username: 'test_for_sdk_2',
name: 'test org sdk 2',
description: 'test organization',
};
const { createOrganization } =
await gateway.organization.createOrganization(obj);
} catch (error) {
console.log(error); // Can log it for degugging
}
}
main();
We have created a separate repository which have more examples you can access it here
All the methods throw a validation error if the validation does not match for example:- invalid wallet, invalid uuid for all ids, Incase of any protocol errors we will throw a custom message which is a string which has all neccessary info regarding error. Make sure to use try catch blocks to handle those.
The Gateway Javascript SDK is licensed under the MIT License.
If you want to support the active development of the SDK. Please go through our Contribution guide
Please read our Code of Conduct before contributing or engaging in discussions.
If you discover a security vulnerability within this package, please open a ticket on Discord. All security vulnerabilities will be promptly addressed.
We are always here to help you. Please talk to us on Discord for any queries.