@tokenrunners/sdk v1.8.0
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();
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago