Thank you for using our SDK.
Our SDK is Promise-based and works on modern environments such as node.js or browsers
NPM
npm i @attarius/sdk
YARN
yarn add @attarius/sdk
import Attarius from '@attarius/sdk';
// const Attarius = require('@attarius/sdk');
const attarius = new Attarius({
apiKey: 'xxxx', //api key from dev panel. Required
endpoint:?? "https://myOwnApi.com" // The optional endpoint in the case of whitelabel. Optional used for user level
userToken?: "" Optional. End user token (you can grab it after authorization)
});
Our SDK can be used on a full environment (like a backend) or a limited environment like a browser or mobile app
Depending on a key type (full or user) SDK disabled some functions and you can use it on browsers and not worry about dangerous functions (like signing a transaction or project level) exposed to the end user.
Real limitation happens on a backend level SDK only middle layer to simplify interaction with
For now, we have keys of two types - full and user. The user key started with the prefix “user:”
await attarius.setUserToken(userToken:string)
Access type - only full key
const uploadedFile = await attarius.api.file.uploadFile({
file: fileToUpload, // refer to section below for node and browser
storageSlug?: string, // The optional slug for storage. Default - default storage
fileName?: string, // The optional. If you want to use a custom file name instead of generated one
});
The upload file structure will be
const response = {
size: number;
name: string;
mimeType: string;
id: string;
url: string;
storage: { name: string; driver: string; slug: string };
alternativeUrls: string[];
decentralizedUrl?: string;
};
fileToUpload variable is different for node.js and browsers
Access type - only full key
const getProjectInfo = await attarius.api.project.getProjectInfo();
Response will be
const response = {
data: {
name: string;
id: string;
description: string;
members: {
_id: string;
name: {
first: string;
last: string;
};
email: string;
avatar: string;
role: string;
}[];
storage: {
name: string;
driver: string;
slug: string;
isDefault: boolean;
isEnabled: boolean;
fileStatistic: {
count: number;
size: number;
};
}[];
apiKeys: {
name: string;
apiKey: string;
permissions: string[];
isActive: boolean;
_id: string;
}[];
}
}
const file = fs.createReadStream('./attarius.png');
<form id="form">
<input type="file" />
</form>
document.getElementById('form').addEventListener('submit', (e) => {
fileToUpload = e.target.files[0];
});
const files = await attarius.api.file.getAll({
page?: number; // current page
limit?: number; // limit of number to return
storageSlug?: string; //filter but storage slug
});
Response will be
const response = {
data: {
size: number;
name: string;
mimeType: string;
id: string;
url: string;
storage: { name: string; driver: string; slug: string };
alternativeUrls: string[];
decentralizedUrl?: string;
}[],
total: number; // total results
page: number; // current page
limit: number; // current limit
}
Access type - only full key
Return networks that the system supports.
await attarius.api.blockchain.getAllNetworks({
page?: number; // current page
limit?: number; // limit of number to return
});
Response will be
const response = {
data: {
key: string;
description: string;
name: string;
frontendProviders: string[];
parameters: {
isTestnet: boolean;
chainId: number;
CAIP2ChainId: string;
explorers: string[];
faucets: string[];
icon: string;
infoURL: string;
rpc: string[];
};
}[],
total: number; // total results
page: number; // current page
limit: number; // current limit
}
Please note this method only works with blockchains that are enabled and have KMS attached to them. It will send the native token to another account
await attarius.api.blockchain.sendNativeToken({
slug: string; // blockchain slug (you can grab it into admin panels)
to: string; // account to receive token
amount: number; // amount in demoninated currency
});
Response will be
const response = {
data: {
hash: string; // transaction hash
explorers: string[]; // link to explorers
}
}
Access type - only full key
Please note this method only works with smart contracts that are enabled and have KMS attached to them. It will transfer the token to another account
await attarius.api.smartContract.transferToken({
slug: string; // smartContract slug (you can grab it into admin panels)
to: string; // account to receive token
amount: number; // amount in demoninated currency
});
Response will be
const response = {
data: {
hash: string; // transaction hash
explorers: string[]; // link to explorers
}
}
Please note this method only works with smart contracts that are enabled and have KMS attached to them. It will mint the token to the provided account
await attarius.api.smartContract.mintNFT({
slug: string; // smartContract slug (you can grab it into admin panels)
to: string; // account to receive token
tokenURI: string; // Optional. Token uri with metadata.
tokenMetadata?: { // Optional. Token metadata directly
name: string; // token name
description: string; //token description
image: string; // token image
attributes?: []; //Optional. attributes - take a llok of the format there https://docs.opensea.io/docs/metadata-standards#attributes
others?: unknown; // Optional. Any other metadata that you want to add
};
});
Please note that "tokenURI" or "tokenMetadata" should be provided (one of them). Name, description and image are required fields for metadata.
Response will be
const response = {
data: {
hash: string; // transaction hash
explorers: string[]; // link to explorers
}
}
Aptos Token works a little bit differently compared to other blockchains. To transfer a token to someone else recipient needs to approve transferring tokens. This is a global option not related to the particular token.
Frontend example for the end user:
const transaction = {
arguments: [true],
function: '0x3::token::opt_in_direct_transfer',
type: 'entry_function_payload',
type_arguments: []
};
await window.aptos.connect()
const pendingTransaction = await window.aptos.signAndSubmitTransaction({payload:transaction});
Access type - full key only
Will return available contract list
const contractList = await attarius.api.nft.getContractList();
Response will be
const response = {
name: string;
slug: string;
}[];
Will all NFT with associated metadata and pagination
const contractList = await attarius.api.nft.getAllNft({
page?: number,
limit?: number,
smartContractSlug?: string // optional smart contract slugg to filter by smart contract
});
Response will be
const response = {
data: {
attariusTokenId: string;
tokenId: string;
owner: string;
metadata: {
name: string;
description: string;
image: string;
attributes: { trait_type: string; value: string }[];
otherValues: object; //any additioanl values from smart contract
}[],
}
total: number; // total results
page: number; // current page
limit: number; // current limit
}
Will one NFT with associated metadata by Attarius NFT id
const contractList = await attarius.api.nft.getById({
id: string,
});
Response will be
const response = {
data: {
attariusTokenId: string;
tokenId: string;
owner: string;
metadata: {
name: string;
description: string;
image: string;
attributes: { trait_type: string; value: string }[];
otherValues: object; //any additioanl values from smart contract
};
}
}
Access type - full key and a user key (limited endpoints). For a user key SDK will return a userToken to authorize the user after. You should store that token somewhere to remember your user. SDK does not store it
For the user key, you can’t select networks - it is driven by the backend only.
Will generate a link to the authenticate users with a blockchain network
const challenge = await attarius.api.authChallenge.createChallenge({
userExternalId?: string; // user External Id. Just for you to associate it with a challenge
networks?: string[]; // an array of keys in CAIP-2 format. If not provided will be used all networks from the project. If the project has no networks then be used all supported networks by the system
});
Response will be
const response = {
id: string; // The special hash of the challenge.
status: string; // status of challenge - can be 'created' or 'solved'
networks: {
driverName: string;
icon: string;
isTestNet: boolean;
network: string;
}[]; // blockchain networks challenge for
userExternalId: string | null; //if an external user id is provided then it will be there
userInternalId: string | null; //if the challenge is solved here you receive an internal user id
expireAt: string; //expiration date. After that date challenge will be deleted
authUrl: string; // url to send the user to authenticate
sourceKeyType: string;
}
Access type - full key only
await attarius.api.authChallenge.getChallenges({
page?: number; // current page
limit?: number; // limit of number to return
});
Response will be
const response = {
data: { // same as creating a challenge
id: string;
status: string;
networks: {
driverName: string;
icon: string;
isTestNet: boolean;
network: string;
}[];
userExternalId: string | null;
userInternalId: string | null;
expireAt: string;
authUrl: string;
sourceKeyType: string;
}[],
total: number; // total results
page: number; // current page
limit: number; // current limit
}
Access type - full key and user key.
const challengeData = await attarius.api.authChallenge.getChallengeById({
challengeId: string;
});
Response will be
const response = { // same as creating a challenge response
id: string;
status: string;
networks: {
driverName: string;
icon: string;
isTestNet: boolean;
network: string;
}[];
userExternalId: string | null;
userInternalId: string | null;
expireAt: string;
authUrl: string;
sourceKeyType: string;
userToken: string; // ONLY for user API key
}
Wait until the challenge is resolved and resolved promise then The response will be the same as on GetChallengeById
Access type - full key only
const user = await attarius.api.user.getUsers({
page?: number; // current page
limit?: number; // limit of number to return
});
Response will be
const response = {
data: {
id: string;
authorizedChains: {
address: string;
network: string;
driverName: string;
isTestNet: boolean;
icon: string;
}[];
metaData: unknown;
}[];
total: number; // total results
page: number; // current page
limit: number; // current limit
}
const user = await attarius.api.user.getUser({
userId: sting;
});
Response will be
const response = {
id: string;
authorizedChains: {
address: string;
network: string;
driverName: string;
isTestNet: boolean;
icon: string;
}[];
metaData: unknown;
}
const user = await attarius.api.user.unlinkUser({
userId: sting;
});
const user = await attarius.api.user.updateUserMetadata({
userId: string;
metaData: unknown;
});
Response will be
const response = {
id: string;
authorizedChains: {
address: string;
network: string;
driverName: string;
isTestNet: boolean;
icon: string;
}[];
metaData: unknown;
}
Access type - user key only
await attarius.api.user.getMe();
Response will be
const response = {
data: {
id: string;
authorizedChains: {
address: string;
network: string;
driverName: string;
isTestNet: boolean;
icon: string;
}[];
metaData: unknown;
};
}
await attarius.api.user.updateMeUserMetadata();
Response will be
const response = {
data: {
id: string;
authorizedChains: {
address: string;
network: string;
driverName: string;
isTestNet: boolean;
icon: string;
}[];
metaData: unknown;
};
}