✨ The Rarible Protocol Ethereum SDK ✨ enables applications to easily interact with Rarible protocol.
npm install -D @rarible/protocol-ethereum-sdk
- Create sell orders 💰
- Create/accept bid for auctions
- Buy tokens for regular sell orders
- Create Lazy Mint NFT ERC721 and ERC1155 tokens
- Make regular mint
- Transfer tokens
- Burn tokens
The examples below can show how you can implement supported functions in you app.
import { createRaribleSdk } from "@rarible/protocol-ethereum-sdk"
const sdk = createRaribleSdk(web3, env, { fetchApi: fetch })
- web3 - configured with your provider web3js client
- env - environment configuration name, it should accept one of these values 'ropsten' | 'rinkeby' | 'mainnet' | 'e2e'
const order: Order = await sdk.order.sell(request).then(a => a.runAll())
// Sell request example:
const contractErc20Address: Address = '0x0' // your ERC20 contract address
const contractErc721Address: Address = '0x0' // your ERC721 contract address
const tokenId: BigNumber = '0x0' // the ERC721 Id of the token on which we want to place a bid
const sellerAddress: Address = '0x0' // Owner of ERC721 token
const nftAmount: number = 1 // For ERC721 always be 1
const sellPrice: number = 10 // price per unit of ERC721 or ERC1155 token(s)
const request = {
makeAssetType: {
assetClass: "ERC1155",
contract: contractErc721Address,
tokenId: tokenId,
},
maker: sellerAddress,
amount: nftAmount,
originFees: [],
payouts: [],
price: sellPrice,
takeAssetType: {
assetClass: "ERC20",
contract: contractErc20Address
},
}
Returns an object of created order.
const order: Order = await sdk.order.bid(request).then(a => a.runAll())
// Bid request example:
const contractErc20Address: Address = '0x0' // your ERC20 contract address
const contractErc721Address: Address = '0x0' // your ERC721 contract address
const tokenId: BigNumber = '0x0' // the ERC721 Id of the token on which we want to place a bid
const sellerAddress: Address = '0x0' // Owner of ERC721 token
const buyerAddress: Address = '0x0' // Who make a bid
const nftAmount: number = 1 // For ERC721 always be 1
const bidPrice: number = 10 // price per unit of ERC721 or ERC1155 token(s)
const request = {
makeAssetType: {
assetClass: "ERC20",
contract: contractErc20Address,
},
maker: buyerAddress,
takeAssetType: {
assetClass: "ERC721",
contract: contractErc721Address,
tokenId: tokenId,
},
taker: sellerAddress,
amount: nftAmount,
originFees: [],
payouts: [],
price: bidPrice,
}
Returns an object of created bid order.
Bid e2e test
const order: SimpleOrder
sdk.order.fill(
order,
{ payouts: [], originFees: [], amount: 1, infinite: true }
).then(a => a.runAll())
For example, you can get the order object using our sdk api methods sdk.apis.order.getSellOrders({}) and pass it to fill function. You can get more information in the test repository sell e2e test
Mint NFT Tokens There are support two ways of minting ERC721 and ERC1155 tokens:
- Regular "on chain" minting using contract.
- Off chain minting (the transaction itself and payment for gas occurs at the time of purchase or transfer)
const mintRequest = {
collection: {
id: toAddress(contractAddress), // contract address
type: "ERC1155", // type of asset to mint, "ERC721" || "ERC1155"
supportsLazyMint: true, // true if contract supports lazy minting
},
uri: 'uri', // token uri
supply: toBigNumber('100'), // supply - used only for ERC1155 tokens
creators: [{ account: toAddress(minter), value: 10000 }], // creators of token
royalties: [], // royalties
lazy: true, // true if mint lazy or false when mint onchain
}
Mint examples Mint function always return tokenId as string
const tokenId = await mint({
collection: {
id: toAddress(contractAddress),
type: "ERC721",
supportsLazyMint: true,
},
uri: 'uri',
creators: [{ account: toAddress(minter), value: 10000 }],
royalties: [],
lazy: true,
})
const tokenId = await mint({
collection: {
id: toAddress(contractAddress),
type: "ERC1155",
supportsLazyMint: true,
},
uri: 'uri',
supply: toBigNumber('100'),
creators: [{ account: toAddress(minter), value: 10000 }],
royalties: [],
lazy: true,
})
await mint({
collection: {
id: toAddress(contractAddress),
type: "ERC721",
supportsLazyMint: true,
},
uri: 'uri',
creators: [{ account: toAddress(minter), value: 10000 }],
royalties: [],
})
const tokenId = await mint({
collection: {
id: toAddress(contractAddress),
type: "ERC1155",
supportsLazyMint: true,
},
uri: 'uri',
supply: toBigNumber('100'),
creators: [{ account: toAddress(minter), value: 10000 }],
royalties: [],
})
Mint e2e test
transfer(asset, to[, amount])
Transfer request params:
asset: {
tokenId: BigNumber, // - id of token to transfer
contract: Address, // - address of token contract
assetClass?: "ERC721" | "ERC1155" // - not required, type of asset
}
to: Address, // - ethereum address of receiver of token
amount: BigNumber // - amount of asset to transfer, used only for ERC1155 assets
Example
const hash = await sdk.nft.transfer(
{
assetClass: "ERC1155",
contract: toAddress(contractAddress),
tokenId: toBigNumber(tokenId),
},
receiverAddress,
toAddress('10')
)
const hash = await sdk.nft.burn({
contract: contractAddress,
tokenId: toBigNumber(tokenId),
})
You are welcome to suggest features and report bugs found! You can do it here: https://github.com/rarible/protocol-issues/issues