0.8.1 • Published 2 months ago

@attarius/sdk v0.8.1

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
2 months ago

Attarius network JavaScript SDK

Thank you for using our SDK.

Our SDK is Promise-based and works on modern environments such as node.js or browsers

Installation

NPM

npm i @attarius/sdk

YARN

yarn add @attarius/sdk

Initialization

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)
});

API keys

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:”

Set user token

await attarius.setUserToken(userToken:string)

Files

Access type - only full key

Upload a file

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

Project

Access type - only full key

Get project info

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;
  }[];
  }

}

Node JS

const file = fs.createReadStream('./attarius.png');

Browser

<form id="form">
  <input type="file" />
</form>
document.getElementById('form').addEventListener('submit', (e) => {
  fileToUpload = e.target.files[0];
});

GetFiles

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
}

Blockchain

Access type - only full key

GetNetworks

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
}

Send native token

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
  }
}

SmartContract

Access type - only full key

Transfer token

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
  }
}

Mint NFT

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 note

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});

NFT

Access type - full key only

GetContractList

Will return available contract list

const contractList = await attarius.api.nft.getContractList();

Response will be

const response = {
  name: string;
  slug: string;
}[];

GetAllNft

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
}

GetById

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
    };
  }
}

Auth Challenge

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.

Сreate Auth Challenge

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;
}

GetChallenges

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
}

GetChallengeById

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

}

Track the status of the Auth Challenge

Wait until the challenge is resolved and resolved promise then The response will be the same as on GetChallengeById

User - full key

Access type - full key only

GetUsers

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
}

GetUser

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;
}

Unlink user

const user = await attarius.api.user.unlinkUser({
  userId: sting;
});

Update User's metadata

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;
}

User - user key

Access type - user key only

Get user details

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;
  };
}

Update user details

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;
  };
}
0.8.1

2 months ago

0.8.0

2 months ago

0.7.0

2 months ago

0.6.2

4 months ago

0.6.1

4 months ago

0.6.0

4 months ago

0.5.3

6 months ago

0.5.2

11 months ago

0.5.0

1 year ago

0.5.1

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.3.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.3.1

1 year ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago