4.5.2 • Published 1 year ago

@refinableco/refinable-sdk v4.5.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

refinable-sdk

refinable-sdk is a NPM package that can be added to the project to work with Refinable contracts.

Get started

TL;DR - Run the examples against testnet

We have created some examples inside of the examples directory. These illustrate the functionality of the SDK and are easily executable.

How to run the 721 mint example

  1. yarn install
  2. PRIVATE_KEY=<your private key> API_KEY=<refinable api key> npx ts-node ./examples/mint/mint721.ts

After executing this, you can view your nft at https://app-testnet.refinable.com/.

These are just example scripts we wrote, the PRIVATE_KEY is only to initialize the ethers provider. We do not send or save your private key anywhere. Please view the example script for the details on this.

How to configure everything

To get started, create an instance of the refinable sdk.

import { Refinable } from "@refinableco/refinable-sdk";

const refinable = await Refinable.create(wallet, "API_KEY", {
  // Optional options
});

Where there are some arguments |Argument|Description|Values| |---|---|---| |wallet | The Provider that is allowed to call functions. | Ethers Signer | |Api Key|The API key, obtained from Refinable|string| |options|Options for customizing the SDK|RefinableOptions| |options.environment|Define the environment (mandatory)|Environment.Testnet or Environment.Mainnet| |options.waitConfirmations|How many confirmations do you want to wait for before continuing|number|

Initialize wallet

To write scripts with our SDK, you'll need to initialize a wallet. When you're doing this from a user-facing platform like a browser. You do not need this as you'll be able to pass the provider injected by metamask. For initializing the wallet you can rely on the added helper factories. When initializing your wallet, please select a chain you want to connect to. Currently the supported chains are BscTestnet, BscMainnet, PolygonTestnet, PolygonMainnet, Ethereum, EthereumRinkeby.

import { initializeWallet, Chain } from "@refinableco/refinable-sdk";

const wallet = initializeWallet(PRIVATE_KEY, Chain.BscTestnet);
const address = await wallet.getAddress();

Methods

Minting a new NFT

import { StandardRoyaltyStrategy, Chain } from "@refinableco/refinable-sdk";
import * as fs from "fs";
import * as path from "path";

// ...

// Upload the file
const fileStream = fs.createReadStream(path.join(__dirname, "./image.jpg"));

// SDK: mint nft
const nft = await refinable
  .nftBuilder()
  .erc721({
    // We accept any type of filestream here, you can also just download it and pass that steam
    nftFile: fileStream,
    description: "some test description",
    name: "The Test NFT",
    royalty: new StandardRoyaltyStrategy([]),
    chainId: Chain.BscTestnet,
  })
  .createAndMint();

more detailed examples can be found in the examples folder

Listing for sale

import { TokenType, PriceCurrency, Chain } from "@refinableco/refinable-sdk";

// ...

// This is not needed if you just called the previous mint function
const nft = refinable.createNft({
  type: TokenType.Erc721,
  chainId: Chain.BscTestnet
  contractAddress: "<your NFTs contract address>",
  tokenId: "2",
  // optional, mostly for ERC1155
  supply: 1
});

// Put for sale
await nft.putForSale({
  amount: 1,
  currency: PriceCurrency.Bnb,
});

putForSale(price: Price, supply?: number): Promise<SaleOffer>

ArgumentDescriptionValues
price.amountThe price that you want to list the NFT for sale fornumber
price.currencyThe currency you want to useView supported currencies
supplyoptional (erc1155) - Only when putting for sale multiple editionsnumber

Cancelling sale

import { TokenType, Chain } from "@refinableco/refinable-sdk";

// ...

// Initialize the existing NFT you want to cancel for sale
const nft = refinable.createNft({
  type: TokenType.Erc721,
  chainId: Chain.BscTestnet
  contractAddress: "<your NFTs contract address>",
  tokenId: "2",
  // optional, mostly for ERC1155
  supply: 1
});

// Cancel sale
await nft.cancelSale();

cancelSale(): Promise<TransactionResponse>

No parameters

Transfering an item

Transfering an item requires you to call the transfer method on the NFT object.

import { TokenType, Chain } from "@refinableco/refinable-sdk";

// ...

// Initialize the existing NFT you want to transfer
const nft = refinable.createNft({
  type: TokenType.Erc721,
  chainId: Chain.BscTestnet
  contractAddress: "<your NFTs contract address>",
  tokenId: "2",
  // optional, mostly for ERC1155
  supply: 1
});

// Example for 721
await nft.transfer("<Owner Wallet Address>", "<Recipient Wallet Address>");

// Example for ERC1155
await nft.transfer("<Owner Wallet Address>", "<Recipient Wallet Address>", 2);

transfer(ownerEthAddress: string, recipientEthAddress: string): Promise<TransactionResponse>

ArgumentDescriptionType
Owner Wallet AddressThe Wallet address that currently owns the NFT, 0x....string
Recipient Wallet AddressThe Recipient wallet address that should receive the NFT, 0x...string
Amountoptional (erc1155) - The amount of editions of that nft you want to sendnumber

Burning an item

For burning an item you need to call burn method on NFT object.

import { TokenType, Chain } from "@refinableco/refinable-sdk";

// ...

// Initialize the existing NFT you want to transfer
const nft = refinable.createNft({
  type: TokenType.Erc721,
  chainId: Chain.BscTestnet
  contractAddress: "<your NFTs contract address>",
  tokenId: "2",
  // optional, mostly for ERC1155
  supply: 1
});

// Example for 721
await nft.burn();

// Example for ERC1155
await nft.burn(2, "<Owner Wallet Address>");

burn(supply?: number, ownerEthAddress?: string): Promise<TransactionResponse>

ArgumentDescriptionType
Supplyoptional (erc1155) - The amount of editions of that nft you want to burnnumber
OwnerEthAddressoptional (erc1155) - The address of the user owning the tokenstring

Listing for Auction

import { TokenType, PriceCurrency, Chain } from "@refinableco/refinable-sdk";

// ...

// Initialize the existing NFT you want to transfer
const nft = refinable.createNft({
  type: TokenType.Erc721,
  chainId: Chain.BscTestnet
  contractAddress: "<your NFTs contract address>",
  tokenId: "2",
  // optional, mostly for ERC1155
  supply: 1
});

// Put for auction
const response = await nft.putForAuction({
  auctionStartDate: new Date(Date.now() + 300000),
  auctionEndDate: new Date(Date.now() + 900000),
  price: {
    amount: 1,
    currency: PriceCurrency.Bnb,
  },
});
ArgumentDescriptionValues
auctionStartDateThe date when the auction is supposed to startDate
auctionEndDateThe date when the auction is supposed to endDate
price.amountThe price that you want to list the NFT for sale fornumber
price.currencyThe currency you want to useView supported currencies

Cancelling an Auction

Cancels an auction, without transfering the NFT.

Example

// Continuation from create auction ...

// Put for auction
const { offer } = await nft.putForAuction({
  auctionStartDate: new Date(Date.now() + 300000),
  auctionEndDate: new Date(Date.now() + 900000),
  price: {
    amount: 1,
    currency: PriceCurrency.Bnb,
  },
});

await offer.cancelAuction();

Ending an auction

Ends an Auction where time has run out. Ending an auction will transfer the nft to the winning bid.

Example

// Continuation from create auction ...

// Put for auction
const { offer } = await nft.putForAuction({
  auctionStartDate: new Date(Date.now() + 300000),
  auctionEndDate: new Date(Date.now() + 900000),
  price: {
    amount: 1,
    currency: PriceCurrency.Bnb,
  },
});

await offer.endAuction();

Fetching data

Getting items for sale

Get all items for-sale of a user

Example

await refinable.getItemsOnSale(<paging number> ,<after string>);
ArgumentDescriptionValues
pagingNumber of items you want to fetch at a timeNumber (default=30 & max=100 )
afterCursor you want to fetch after (endCursor)String (Optional)

Getting items on auction

Get all items on auction of a user

Example

await refinable.getItemsOnAuction(<paging number>, <after string>);
ArgumentDescriptionValues
pagingNumber of items you want to fetch at a timeNumber (default=30 & max=100 )
afterCursor you want to fetch after (endCursor)String (Optional)

Getting owned items for a user

Get all owned items by a user

Example

await refinable.getOwnedItems(<paging>,<after>)
ArgumentDescriptionValues
pagingNumber of items you want to fetch at a timeNumber (default=30 & max=100)
afterCursor you want to fetch after (endCursor)String (Optional)

Getting created items by a user

Get all items created by a user

Example

await refinable.getCreatedItems(<paging>,<after>)
ArgumentDescriptionValues
pagingNumber of items you want to fetch at a timeNumber (default=30 & max=100)
afterCursor you want to fetch after (endCursor)String (Optional)

Supported Networks

Refinable currently supports the following networks:

  • 56: Binance Smart Chain (BSC) Mainnet
  • 97: Binance Smart Chain (BSC) Testnet
  • 137: Polygon Mainnet
  • 80001: Polygon Mumbai Testnet
  • 1: Ethereum
  • 4: Ethereum Rinkeby Testnet

Supported currencies

NetworkCurrencies
BscMainnetBNB, USDT, BUSD
BscTestnetBNB, USDT, BUSD
PolygonMainnetMATIC, USDT, WETH
PolygonTestnetMATIC
EthereumETH, USDT, WETH, USDC
EthereumRinkebyETH, USDT, WETH, USDC

Requesting an API Key

In order to obtain an API key, please email us at sdk@refinable.com and use the following template:

Project NameThe name of your project
User addressThe public wallet address that the API key will be attached to, This user should have connected to the Refinable site at least once
Est. Calls per monthThe amount of estimated calls per month
DescriptionTell us a bit more about your project, why do you have to use an SDK?

Jobs

Interested in joining us? We're always on the lookout for good talent. Feel free to send us your most up-to-date resume at careers@refinable.com

4.7.0-next.0

2 years ago

4.5.0-next.0

2 years ago

4.5.0-next.1

2 years ago

4.5.0-next.2

2 years ago

4.5.0-next.3

2 years ago

4.5.0-next.4

2 years ago

4.5.2

2 years ago

4.5.1

2 years ago

4.6.1-next.0

2 years ago

5.0.0-next.1

2 years ago

5.0.0-next.2

2 years ago

5.0.0-next.0

2 years ago

5.0.0-next.5

2 years ago

5.0.0-next.6

2 years ago

5.0.0-next.3

2 years ago

5.0.0-next.4

2 years ago

5.0.0-next.7

2 years ago

5.0.0-next.8

1 year ago

4.4.0-next.1

2 years ago

4.5.1-next.0

2 years ago

4.2.2-next.0

2 years ago

4.2.16-next.3

2 years ago

4.2.16-next.2

2 years ago

4.2.16-next.1

2 years ago

4.2.13-next.0

2 years ago

4.2.17-next.0

2 years ago

4.2.16-next.0

2 years ago

4.3.0-next.0

2 years ago

4.2.12-next.0

2 years ago

4.3.0-next.4

2 years ago

4.3.0-next.3

2 years ago

4.3.0-next.2

2 years ago

4.3.0-next.1

2 years ago

4.2.20

2 years ago

4.2.21

2 years ago

4.2.7-next.0

2 years ago

4.2.5-next.0

2 years ago

4.2.7-next.1

2 years ago

4.2.7-next.2

2 years ago

4.2.7-next.3

2 years ago

4.2.7-next.4

2 years ago

4.2.0-next.2

2 years ago

4.2.0-next.3

2 years ago

4.2.0-next.4

2 years ago

4.2.0-next.5

2 years ago

4.2.0-next.6

2 years ago

4.2.0-next.7

2 years ago

4.2.0-next.8

2 years ago

4.3.1

2 years ago

4.2.0-next.9

2 years ago

4.3.0

2 years ago

4.2.19

2 years ago

4.2.8-next.0

2 years ago

4.2.15-next.0

2 years ago

4.2.14-next.0

2 years ago

4.2.19-next.0

2 years ago

4.2.18-next.0

2 years ago

4.2.3

2 years ago

4.2.4

2 years ago

4.2.1

2 years ago

4.2.0

2 years ago

4.2.11-next.0

2 years ago

4.2.10-next.0

2 years ago

4.4.0-next.0

2 years ago

4.2.7

2 years ago

4.2.6

2 years ago

4.2.0-next.10

2 years ago

4.1.0-next.1

2 years ago

4.1.0-next.2

2 years ago

4.1.0-next.0

2 years ago

4.1.0-next.3

2 years ago

4.1.0-next.4

2 years ago

3.0.2-next.1

2 years ago

3.1.0-next.8

2 years ago

3.0.2-next.2

2 years ago

3.1.0-next.7

2 years ago

3.1.0-next.6

2 years ago

3.0.2-next.0

2 years ago

3.0.2-next.3

2 years ago

3.1.0-next.1

2 years ago

3.1.0-next.0

2 years ago

3.1.0-next.5

2 years ago

3.1.0-next.4

2 years ago

3.1.0-next.3

2 years ago

3.1.0-next.2

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.2.0-next.0

2 years ago

4.2.0-next.1

2 years ago

3.0.4-next.1

2 years ago

3.0.0-next.2

2 years ago

3.0.0-next.1

2 years ago

3.0.0-next.4

2 years ago

3.0.0-next.3

2 years ago

3.0.0-next.0

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

4.0.0-next.0

2 years ago

3.0.3-next.1

2 years ago

2.3.3-next.1

2 years ago

2.3.1-next.1

2 years ago

2.3.3-next.0

2 years ago

2.3.1-next.0

2 years ago

2.3.0-next.12

2 years ago

2.3.1-next.2

2 years ago

2.3.0-next.13

2 years ago

2.3.0-next.10

2 years ago

2.3.0-next.11

2 years ago

2.3.3-next.3

2 years ago

2.3.3-next.2

2 years ago

2.3.0-next.9

2 years ago

2.3.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.2.0

2 years ago

2.2.0-next.2

2 years ago

2.2.0-next.3

2 years ago

2.3.0-next.7

2 years ago

2.2.0-next.4

2 years ago

2.3.0-next.8

2 years ago

2.3.0-next.1

2 years ago

2.3.0-next.2

2 years ago

2.3.0-next.0

2 years ago

2.3.0-next.5

2 years ago

2.3.0-next.6

2 years ago

2.3.0-next.3

2 years ago

2.3.0-next.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.1.0-next.2

2 years ago

2.1.0-next.1

2 years ago

2.1.0-next.3

2 years ago

2.1.0-next.0

2 years ago

2.2.0-next.1

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0-next.20

2 years ago

2.0.0-next.15

2 years ago

1.2.0

2 years ago

2.0.0-next.16

2 years ago

2.0.0-next.17

2 years ago

2.0.0-next.8

2 years ago

2.0.0-next.18

2 years ago

2.0.0-next.9

2 years ago

2.0.0-next.19

2 years ago

2.0.0-next.6

2 years ago

2.0.0-next

2 years ago

2.0.0-next.7

2 years ago

2.0.0-next.4

2 years ago

2.0.0-next.5

2 years ago

2.0.0-next.10

2 years ago

1.2.5

2 years ago

2.0.0-next.11

2 years ago

1.2.4

2 years ago

2.0.0-next.12

2 years ago

1.2.3

2 years ago

2.0.0-next.13

2 years ago

1.2.2

2 years ago

2.0.0-next.14

2 years ago

1.2.1

2 years ago

2.0.0-next.3

2 years ago

1.3.3-next.1

2 years ago

1.3.3-next.2

2 years ago

1.3.3-next.3

2 years ago

2.0.2-next

2 years ago

1.3.3-next.0

2 years ago

2.0.1-next

2 years ago

1.1.8

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.1.11

2 years ago

1.1.10

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago