Skip to content

Getting Started

Installation

sh
$ npm i @shadeprotocol/shadejs
$ npm i @shadeprotocol/shadejs
sh
$ yarn add @shadeprotocol/shadejs
$ yarn add @shadeprotocol/shadejs

Example Query

Standard Syntax

ts
/*
* Queries the configuration for the swap pair
*/
async function queryPairConfig({
  contractAddress,
  codeHash,
  lcdEndpoint,
  chainId,
}:{
  contractAddress: string,
  codeHash?: string, // recommended for fastest query performance
  lcdEndpoint?: string, // defaults to public endpoint
  chainId?: string, // defaults to mainnet
}): Promise<PairConfig>
/*
* Queries the configuration for the swap pair
*/
async function queryPairConfig({
  contractAddress,
  codeHash,
  lcdEndpoint,
  chainId,
}:{
  contractAddress: string,
  codeHash?: string, // recommended for fastest query performance
  lcdEndpoint?: string, // defaults to public endpoint
  chainId?: string, // defaults to mainnet
}): Promise<PairConfig>

WARNING

The LCD endpoint is an optional property. We provide one as a default inside ShadeJS to get you started quickly on Secret Network mainnet using a public API. It is still recommended that you provide your own because performance of the default endpoint is not guaranteed.

ts
try{
  const output = await queryPairConfig({
    contractAddress: '[PAIR_CONTRACT_ADDRESS]',
  })
 // do something with the successful output
} catch {
  // do something with the error
}
try{
  const output = await queryPairConfig({
    contractAddress: '[PAIR_CONTRACT_ADDRESS]',
  })
 // do something with the successful output
} catch {
  // do something with the error
}

RxJS Syntax

Under the hood, ShadeJS uses RxJS as an observables library to build asynchronous functions. The async functions provided for interacting with the blockchain have an RxJS version as an alternative, and users can decide which one to use based on their preference.

TIP

The standard async/await syntax function is designed as a simple wrapper function around the RxJS, so either way you are calling the RxJS version!

ts
/*
* Queries the configuration for the swap pair
*/
function queryPairConfig$({
  contractAddress,
  codeHash,
  lcdEndpoint,
  chainId,
}:{
  contractAddress: string,
  codeHash?: string, 
  lcdEndpoint?: string,
  chainId?: string,
}): Observable<PairConfig>
/*
* Queries the configuration for the swap pair
*/
function queryPairConfig$({
  contractAddress,
  codeHash,
  lcdEndpoint,
  chainId,
}:{
  contractAddress: string,
  codeHash?: string, 
  lcdEndpoint?: string,
  chainId?: string,
}): Observable<PairConfig>
ts
queryPairConfig$({
  contractAddress: '[PAIR_CONTRACT_ADDRESS]',
}).subscribe({
  next: () => {
    // do something with the successful output
  },
  error: () => {
  // do something with the error
  }
})
queryPairConfig$({
  contractAddress: '[PAIR_CONTRACT_ADDRESS]',
}).subscribe({
  next: () => {
    // do something with the successful output
  },
  error: () => {
  // do something with the error
  }
})

Contract Registry

You can access the Shade mainnet and testnet contract registry here.