1.8.0 • Published 2 years ago

@tokenrunners/sdk v1.8.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Token Runners SDK

A client facing SDK library for interacting with the token runners application and the blockchain.

Installing

Install the following packages in your project

npm i --save @tokenrunners/sdk@1.5.0
npm i --save-dev @tokenrunners/plugin

The webpack plugin

Create a file called webpack.config.js on the root of your project, this guide assumes you're using nullstack.

const [ server, client ] = require('nullstack/webpack.config');
const { applyTokenRunnersSDKPlugin } = require('@tokenrunners/plugin')

module.exports = applyTokenRunnersSDKPlugin([server, client])

Usage

Connect to a wallet


import TokenRunners, { NetworkType, WalletType } from '@tokenrunners/sdk'

const tokenRunnersSdk = new TokenRunners({
  settings: {
    baseURL: 'http://tokenrunners.localhost:3000',
  },
})

async function login() {

  const { token } = await tokenRunnersSdk.connect({
    // blockchain network type
    network: NetworkType.Ethereum,
    // wallet type to use
    walletType: WalletType.Metamask,
  });

  console.log('logged in', token);

}

login();

Disconnecting from a wallet

Assuming we already have the token runners instance and the imports above

async function logout() {

  await tokenRunnersSdk.disconnect({
    // blockchain network type
    network: NetworkType.Ethereum,
    // wallet type to use
    walletType: WalletType.Metamask,
  });

}

logout();

Fetch Store data

In order to fetch the store data and its available filters, you can use this function.

It uses the store url set on initialization as a way to identify the store.

async function fetchStore() {

  const result = await tokenRunnersSdk.fetchStore();

  console.log(result)

}

fetchStore();

Fetch Available NFTs For Sale

This function paginates the nfts that are available for sale on the specified store.

All parameters are optional.

async function fetchNfts() {

  const result = await tokenRunnersSdk.fetchNfts({
    // page?: number; // page number
    // limit?: number; // limit per page
    // collections?: Array<string>; // array of collection ids
    // traits?: Array<string>; // array of trait ids
    // sort?: string; // the sort field
    // order?: number; // the sorting order
    // user?: string; // filters by the owner user id
    // template_id?: string; // filters through the template id
  });

  console.log(result)

}

fetchNfts();

Fetch NFTs Owned by the Current User

This function paginates the nfts that the currently signed in user owns.

All parameters are optional.

async function fetchMyNfts() {

  const result = await tokenRunnersSdk.fetchMyNfts({
    // page?: number; // page number
    // limit?: number; // limit per page
    // collections?: Array<string>; // array of collection ids
    // traits?: Array<string>; // array of trait ids
    // sort?: string; // the sort field
    // order?: number; // the sorting order
    // template_id?: string; // filters through the template id
  });

  console.log(result)

}

fetchMyNfts();

Fetch single NFT

This function fetches a single NFT based on a given template id.

async function fetchOneNft() {

  const result = await tokenRunnersSdk.fetchOneNft({
    // id: string; // Template object id
  });

  console.log(result)

}

fetchOneNft();

Fetch Current User Data

This function fetches the current signed in user data.

async function fetchUser() {

  const result = await tokenRunnersSdk.fetchUser();

  console.log(result)

}

fetchUser();

Patch Current User Data

This function allows you to update the current user data.

async function patchUser() {

  const result = await tokenRunnersSdk.patchUser({
    // firstName?: string;
    // lastName?: string;
    // country?: string;
    // about?: string;
    // emailNotification?: boolean;
    // email?: string;
    // avatarTemplateId?: string;
    // oldPassword?: string;
    // newPassword?: string;
    // confirmPassword?: string;
  });

  console.log(result)

}

patchUser();

Fetch Wallet Balance

This function fetches the current wallet or specified wallet account balance.

async function getBalance() {

  const result = await tokenRunnersSdk.getBalance({
    // addr?: string // wallet address, optional if connected.
  });

  console.log(result)

}

getBalance();

Purchase Token

This function purchases a specified listing in the blockchain.

It uses the currently connected wallet to complete the purchase.

It resolves once the app is updated with the purchase.

It returns the token data and the transaction receipt.

This function can be called for the following solutions:

  • purchase a single token that is being listed.
  • blind purchase one or more tokens in a listing.
  • pre-sale blind purchase one or more tokens in a listing.
async function purchase(listingID) {

  const { tokens, transaction } = await tokenRunnersSdk.purchase({ listingID });

  console.log({ token, transaction })

}

purchase();

Fetch Available Listings

This function paginates the available listings for a store

All parameters are optional.

async function fetchListings() {

  const result = await tokenRunnersSdk.fetchListings({
    // page?: number; // page number
    // limit?: number; // limit per page
    // presale?: boolean; // filters presale listings
    // blindsale?: boolean; // filters blind sale listings (more than 1 token)
  });

  console.log(result)

}

fetchListings();

Fetch single listing

This function fetches a specified listing.

async function fetchListing() {

  const result = await tokenRunnersSdk.fetchListing({
    listingID: 1, // the listing resource id on chain
  });

  console.log(result)

}

fetchListing();

Subscribe user/wallet event

this function adds a on user event subscription to know when a wallet changes

async function subscribeOnUser() {

  const result = await tokenRunnersSdk.onUser(({ wallet, user }) => {
    console.log(wallet, user)
  });

}

subscribeOnUser();
1.8.0

2 years ago

1.6.6

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.6.5

2 years ago

1.4.7

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.10

2 years ago

1.3.11

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.4.6-unstable

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5-unstable

2 years ago

1.0.4-unstable

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago