Initialize SDK and start development


Obtaining an API Key

You should check out Getting Started page to get more information about how to obtain an API key.

The SDK expects four main arguments during the initialization:

  1. API Key: Required for confirming that you have the necessary rights to use the SDK and underlying APIs
  2. Signer: Used to establish connection to the Ethereum network and to send RPC requests
  3. Chain: The blockchain network to operate on
  4. NFT Contracts Info: Addresses of your NFT contracts on both 721 and 1155 standards


What is 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.

Create a Signer

Assuming that you already have an API key to provide, the only thing that's needed to initialize the SDK is a Signer instance. You have two options to create a signer:

  1. Using an injected provider such as MetaMask (recommended)
  2. Initializing with private key or mnemonics and connecting it to an RPC node

Using MetaMask (recommended)

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()

Using Private Key/Mnemonics

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

Specify NFT Contract Addresses

Stash Renting SDK supports rental for NFTs of both 721 and 1155 standards. For the sake of simplicity, it's not required to provide your contract addresses each time you would like to perform an operation. Therefore, the contract addresses should be provided only during the initialization of the SDK.

The SDK expects the addresses in data type NFTContractsInfo with the following structure:

    ERC721ContractAddress: string | null,
    ERC1155ContractAddress: string | null

As you can see in the declaration, it's possible to provide the address for only one standard. If you give null value for the both standards, then you won't be able to execute operations after the initialization of the SDK.

Here are two examples demonstrating a case where both standards are supported and another case where NFTs of only 721 standard are supported:

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

Specify Chain

Available values are Chain.ETH, Chain.GOERLI, Chain.BSC, Chain.POLYGON

Binance Smart ChainChain.BSC
Binance Smart Chain TestnetChain.BSC_TESTNET

Initialize Stash Core

Assuming that you have a valid API key, a signer and also the contract information; all you need to do is to initialize the SDK with the chain to operate on. You can check either Supported Chains section to see the list of the permitted values for the chain parameter.

The initialization can be performed as follows:

import { Stash } from 'stash-renting-sdk';
const stash = new Stash(<apiKey>, signer, <chain>, contractsInfo);
// If you are using Private Key/Mnemonics to create a signer, you can replace the "signer" variable with "wallet"

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:

Next up

Check if your NFTs are compatible for renting and learn how to make them compatible if it's needed