npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@attarius/sdk

v0.8.1

Published

Attarius network Node/Browser SDK

Downloads

73

Readme

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