A quick guide to start out with Stash SDK

Stash SDK is currently available in Typescript. Python & Rust versions are upcoming.


Install with npm

$ npm install stash-renting-sdk

Getting Started

Retrieve an API Key

In order to use Stash Renting SDK and APIs, you need to provide an API key to the SDK. If you want to use Stash's technologies for your own game or platform, please contact us here or fill out the form here to retrieve your API key and start building right away!

Initialize the SDK

Create a Signer



A Signer in ethers is an abstraction of an Ethereum Account, which can be used to sign messages and transactions and send signed transactions to the Ethereum Network to execute state changing operations.

The most common *Signers you will encounter are:

  • Wallet, which is a class which knows its private key and can execute any operations with it.
  • JsonRpcSigner, which is connected to a JsonRpcProvider

You need to have a Signer object to initialize the SDK, so that connection to the Ethereum Network can be established and contract functions can be called.

Using MetaMask

The easiest and quickest way to produce a signer is using MetaMask. The example below describes a case where user is asked to connect his or her MetaMask account and the signer is initialized through the connected account:

// A Web3Provider wraps a standard Web3 provider, which is
// what MetaMask injects as window.ethereum into each page
const provider = new ethers.providers.Web3Provider(window.ethereum);

// Ask user to connect its MetaMask account(s)
await provider.send("eth_requestAccounts", []);

// Retrieve the signer
const signer = provider.getSigner()


Another option is to produce a signer in form of a Wallet by using its private key or mnemonic.
The code sample below illustrates how to initialize a Wallet and to connect it to a JSON RPC provider (localhost or Infura, Alchemy, etc.):

import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';

// Initialize the provider
const provider = new JsonRpcProvider(<providerUrl>);

// Initialize the wallet with either private key or mnemonic
let wallet = new Wallet(<privKey_or_mnemonic>);

// Connect wallet to provider
wallet = wallet.connect(provider);

Initialize Stash Core

Assuming that you have a valid API key and a signer, all you need to do is to initialize the SDK with the chain to operate on and your NFT (ERC-721 or 1155) contract address(es).


Supported Chains

You can check either Supported Chains section in the documentation or the declaration of Chain data type under src/types.ts to see the list of the permitted values for the chain parameter.

NFT contract addresses for both standards (721 and 1155) are encapsulated in type NFTContractsInfo with the following declaration:

export declare type NFTContractsInfo = {
    ERC721ContractAddress: string | null;
    ERC1155ContractAddress: string | null;

You can leave the address field empty for a certain standard, if you have NFTs for only one single standard. There are two code snippets for both standards and only for 721 down below:

const contractsInfo = {
  ERC721ContractAddress: "0x6fa5657447f9f3c2ed41b30448d59d74e3ff2938",
  ERC1155ContractAddress: "0x9fk4657447f9f3c2ed41b30448d59d74e3gr39j2"
const contractsInfo = {
  ERC721ContractAddress: "0x6fa5657447f9f3c2ed41b30448d59d74e3ff2938"

Assuming that you have a valid signer and specified the NFT contract information, you're now good to go with initializing the SDK. The initialization can be performed as follows:

import { Stash } from 'stash-renting-sdk';
const stash = new Stash(<apiKey>, wallet, <chain>, contractsInfo);

After the initialization of the SDK, it also loads the necessary contracts based on the network and makes them available to use for further operations (e.g. lending, renting).

And that's it. We are ready to go :rocket: