npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rarible/flow-sdk

v0.5.78-fix.3

Published

SDK for interact with flow blockchain and Rarible protocol

Downloads

748

Readme

Flow SDK

Installation

npm i -S @rarible/flow-sdk

Usage

Simple code example

Quick start

  1. Configure fcl
  2. Create and use flow-sdk

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: toBigNumber("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")