@rarible/flow-sdk
v0.6.0-beta.1
Published
SDK for interact with flow blockchain and Rarible protocol
Downloads
803
Readme
Flow SDK
Installation
npm i -S @rarible/flow-sdk
Usage
Simple code example
Quick start
Configure fcl
Flow-sdk use @onflow/fcl-js. You can find configuration details for fcl in this page
//example config for testnet
import { config } from "@onflow/fcl";
config({
"accessNode.api": "https://access-testnet.onflow.org", // Mainnet: "https://access-mainnet-beta.onflow.org"
"discovery.wallet": "https://fcl-discovery.onflow.org/testnet/authn" // Mainnet: "https://fcl-discovery.onflow.org/authn"
})
Create and use flow-sdk
Then we create the SDK according to the network that we configured in the previous step.
import { createFlowSdk } from "@rarible/flow-sdk"
import * as fcl from "@onflow/fcl"
const sdk = createFlowSdk(fcl, "testnet")
Minting
Mint response represents transaction result extended with txId
and minted tokenId
import { toFlowContractAddress } from "@rarible/flow-sdk"
import { toFlowAddress } from "@rarible/types"
// collection = Contact address A.[contactAddress].[contractName]
const collection = toFlowContractAddress("A.0x1234567890abcdef.RaribleNFT")
// royalties - array of objects: {account: FlowAddress, value: BigNumber}, value must be a number between 0 and 1
const royalties = [{ account: toFlowAddress("0x1234567890abcdef"), value: toBigNumberLike("0.1") }]
const metaData = "your meta info" // usually ipfs url
const { tokenId } = await sdk.nft.mint(collection, metaData, royalties)
Returns FlowTransaction
object with minted tokenId
Transfer
import { toFlowAddress } from "@rarible/types"
import { toFlowContractAddress } from "@rarible/flow-sdk"
const collection = toFlowContractAddress("A.0x1234567890abcdef.RaribleNFT")
const tokenId = 123
const receiver = toFlowAddress("0x1234567890abcdef")
const tx = await sdk.nft.transfer(collection, tokenId, receiver)
Returns FlowTransaction
object
Burn
import { toFlowContractAddress } from "@rarible/flow-sdk"
const collection = toFlowContractAddress("A.0x1234567890abcdef.RaribleNFT")
const tokenId = 123
const tx = await sdk.nft.burn(collection, tokenId)
Returns FlowTransaction
object
Create sell order
import { toFlowContractAddress, toFlowItemId } from "@rarible/flow-sdk"
const collection = toFlowContractAddress("A.0x1234567890abcdef.RaribleNFT")
const itemId = toFlowItemId(`${collection}:123`)
const tx = await sdk.nft.sell(collection, currency, itemId, price)
/** supported currencies for now "FLOW" and "FUSD" */
/** FlowItemId you can find in FlowNftItem response from api,
for example sdk.apis.item.getNftItemsByOwner({address: <your account address>})
*/
/** price must be a string of flow fungible token amount with 8 decimals, for example: 1.123 or 0.1 or 0.00000001 */
Returns FlowTransaction
object with orderId
Update order
const tx = await sdk.nft.updateOrder(collection, currency, orderId, price)
// orderId can be a orderId number or full FlowOrder object received from order api
Returns FlowTransaction
object with updated orderId
Cancel order
const tx = await sdk.nft.cancelOrder(collection, orderId)
Returns FlowTransaction
object
Buy an item
const tx = await sdk.nft.fill(collection, orderId, owner)
// owner: FlowAddress - order owner address
Returns FlowTransaction
object
Create bid
import { toFlowContractAddress, toFlowItemId } from "@rarible/flow-sdk"
const collection = toFlowContractAddress("A.0x1234567890abcdef.RaribleNFT")
const itemId = toFlowItemId(`${collection}:123`)
const tx = await sdk.nft.bid(collection, currency, itemId, price)
// params the same as regular order creation
Returns FlowTransaction
object with orderId
Update bid
const tx = await sdk.nft.updateBid(collection, currency, bidId, price)
Returns FlowTransaction
object with updated orderId
Cancel bid
const tx = await sdk.nft.cancelBid(collection, bidId)
Returns FlowTransaction
object
Accept bid
The same as buy order sdk.order.fill
Get account fungible tokens balance
const balance = await sdk.wallet.getFungibleBalance(accountAddress, "FUSD")