@uniblock/rarible v0.0.1-5
uniblock-sdk
This is a wrapper sdk around the Rarible sdk.
Setup
Follow this step to add @uniblock/rarible to your repository
npm i @uniblock/rarible
or
yarn add @uniblock/rarible
General Overview
This sdk is a wrapper around rarible sdk. Through these wrappers we allow users to create Collections, NFTs, and Bids and Sell Orders. Together users can use these functionalities to create an NFT marketplace that can allow users to create, sell, and purchase NFTs. Rarible supports features like lazy-Minting, royalties and allows for bidding using any ERC-20 token. Some use cases and implementations are highlighted on Rarible's page In summary, users using this SDK can take the daunting tasks of writing contracts and contract interaction of creating an NFT marketplace away and focus on creating a refined marketplace for minting, buying, and selling NFTs
Quick Start
Make sure to add the '@uniblock/rarible' package to your project at this point, the proceeding steps will assume that you have done so.
Initialize wallet and uniblock/rarible sdk
In order to get provider we can use any method, metamask docs >>
const provider = (await detectEthereumProvider() as ethers.providers.ExternalProvider);
if (provider) {
const ethersWeb3Provider = new ethers.providers.Web3Provider(provider);
const ethersProvider = new EthersWeb3ProviderEthereum((ethersWeb3Provider as any));
const ethWallet = new EthereumWallet(ethersProvider);
const rarible = await initializeRarible(ethWallet, 'testnet', 'YOUR_UNIBLOCK_KEY');
}
Create a collection
Pass in the following arguments to create a collection
const ethereumRequest: CreateCollectionRequest = {
blockchain: ApiClient.Blockchain.POLYGON,
asset: {
assetType: 'ERC721',
arguments: {
name: 'MyNFT',
symbol: 'MyNFT',
baseURI: 'https://mybaseuri',
contractURI: ' https://api-rinkeby.rarible.com/contractMetadata',
isUserToken: false,
},
},
};
const result = await rarible.createCollection(ethereumRequest);
Mint NFT
Pass in the following arguments to create an NFT
const mintArgs = {
uri: 'https://mybaseuri/636762',
lazyMint: false,
supply: 1,
};
const collectionAddress = 'CHAIN:COLLECTIONID';
const result = await rarible.mint(mintArgs, collectionAddress);
List NFT for Sell
Pass in the following arguments to create a Sell Order
const orderArgs: OrderRequest = {
amount: 1,
price: '0.0000420',
currency: { '@type': 'ETH' },
};
const result = await rarible.sell(orderArgs, NFTS[0].itemId);
Mint And Sell in together
Pass in the following arguments to both mint a NFT and list it for sale
const NFTArgs: MintAndSellRequest = {
uri: 'baseurl/6336f161e13e6063dcbb696d',
lazyMint: false,
supply: 1,
price: '0.1',
currency: { '@type': 'ETH' },
};
const collectionAddress = 'NETWORK:COLLECTIONADDRESS';
const result = await rarible.mintAndSell(NFTArgs, collectionAddress);
Bid on NFT
Pass in the following arguments to Bid on an NFT
const bidArgs: OrderRequest = {
amount: 1,
price: '0.0000691',
currency: {
'@type': 'ERC20',
contract: 'POLYGON:0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889', //WMATIC address or WETH or any token that will be used to pay
},
};
const result = await rarible.bid(bidArgs, 'NETWORK:COLLECTIONADDRESS:ITEMID');
Accept Bid on NFT
Pass in the following arguments to accept a bid on an NFT
const acceptArgs: FillRequest = {
amount: 1,
};
const result = await rarible.acceptBid(acceptArgs, 'ORDERID');