Rarible Protocol Ethereum SDK enables applications to easily interact with Rarible protocol.
npm install -D @rarible/protocol-ethereum-sdk
or inject package into your web page with web3 instance
<script src="https://unpkg.com/@rarible/[email protected]/umd/rarible-web3-ethereum.js" type="text/javascript"></script>
<script src="https://unpkg.com/@rarible/[email protected]/umd/rarible-ethereum-sdk.js" type="text/javascript"></script>
<script src="https://unpkg.com/[email protected]/dist/web3.min.js" type="text/javascript"></script>
- 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
You can view the reference for the latest version of the API or choose API on different Ethereum networks.
Below examples 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 web = new Web3(ethereum)
const web3Ethereum = new window.raribleWeb3Ethereum.Web3Ethereum({ web3: web })
const env = "mainnet" // "e2e" | "ropsten" | "rinkeby" | "mainnet"
const raribleSdk = new window.raribleEthereumSdk.createRaribleSdk(web3Ethereum, env)
- ethereum - metamask browser instance (window.ethereum)
Сheck out our DEMO PAGE
const order: Order = await sdk.order.sell(request)
// 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)
// 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.
const order: SimpleOrder
sdk.order.fill({ order, payouts: [], originFees: [], amount: 1, infinite: true })
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
You can mint ERC721 and ERC1155 tokens in two ways:
- Regular "on chain" minting using contract.
- Off chain minting (the transaction itself and payment for gas occurs at the time of purchase or transfer).
You can use mint to create a token in different collections. Depending on the collection type, different mint requests should be sent to the function (isErc1155v1Collection, isErc1155v2Collection etc).
Mint function checks:
- Request for MintOffChainResponse or MintOnChainResponse.
- Token type: ERC721 or ERC1155.
Differences between mint functions in the presence of arguments creators
, supply
and lazy
:
creators
not use in ERC1155 v1supply
used only for ERC1155 v1 and v2lazy
is used if the passed collection supports lazy mint. Otherwise, the usual mint will be performed
For more information, see mint.ts.
ERC1155 V2 Lazy example:
return mint({
collection, // Collection info
uri: "", // Token URI
royalties: [], // The amount of royalties
supply: 1, // Number of the tokens to mint, used only for ERC1155
creators: [], // Creators of token
lazy: true, // The token will be lazy minted or not
})
For more information, see mint.md.
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
Rarible Protocol Ethereum SDK is available under the MIT license.