0.6.0-beta.0 • Published 10 months ago

@rarible/flow-sdk v0.6.0-beta.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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: 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")
0.6.0-beta.0

10 months ago

0.5.80

10 months ago

0.5.79

10 months ago

0.5.78-fix.9

10 months ago

0.5.78-fix.8

10 months ago

0.5.78-fix.7

11 months ago

0.5.78-fix.6

11 months ago

0.5.78-fix.3

1 year ago

0.5.78-fix.2

1 year ago

0.5.78-fix.1

1 year ago

0.5.78-fix.0

1 year ago

0.5.78

1 year ago

0.5.76-beta.0

1 year ago

0.5.77-fix.0

1 year ago

0.5.77-fix.1

1 year ago

0.5.77

1 year ago

0.5.76

2 years ago

0.5.73-fix.0

2 years ago

0.5.74

2 years ago

0.5.72

2 years ago

0.5.73

2 years ago

0.5.70

2 years ago

0.5.71

2 years ago

0.5.69

2 years ago

0.5.75-fix.1

2 years ago

0.5.74-fix.0

2 years ago

0.5.74-fix.1

2 years ago

0.5.65

2 years ago

0.5.66

2 years ago

0.5.63

2 years ago

0.5.64

2 years ago

0.5.61

2 years ago

0.5.62

2 years ago

0.5.60

2 years ago

0.5.67

2 years ago

0.5.68

2 years ago

0.5.59

2 years ago

0.5.54

2 years ago

0.5.55

2 years ago

0.5.52

2 years ago

0.5.53

2 years ago

0.5.50

2 years ago

0.5.51

2 years ago

0.5.58

2 years ago

0.5.56

2 years ago

0.5.57

2 years ago

0.5.48-alpha.0

3 years ago

0.5.48-alpha.1

3 years ago

0.5.48-alpha.2

3 years ago

0.5.48-alpha.3

3 years ago

0.5.48-alpha.5

3 years ago

0.5.47

3 years ago

0.5.41-alpha.1

3 years ago

0.5.33-alpha.28

3 years ago

0.5.33-alpha.27

3 years ago

0.5.42-alpha.2

3 years ago

0.5.42-alpha.1

3 years ago

0.5.43

3 years ago

0.5.44

3 years ago

0.5.40

3 years ago

0.5.45

3 years ago

0.5.46

3 years ago

0.5.39

3 years ago

0.5.33-alpha.26

3 years ago

0.5.30-ac.0

4 years ago

0.5.33-alpha.10

3 years ago

0.5.33-alpha.12

3 years ago

0.5.33-alpha.11

3 years ago

0.5.33-alpha.18

3 years ago

0.5.33-alpha.17

3 years ago

0.5.33-alpha.19

3 years ago

0.5.33-alpha.14

3 years ago

0.5.33-alpha.13

3 years ago

0.5.33-alpha.16

3 years ago

0.5.33-alpha.15

3 years ago

0.5.33-alpha.21

3 years ago

0.5.29-hotfix.1

3 years ago

0.5.33-alpha.20

3 years ago

0.5.33-alpha.23

3 years ago

0.5.33-alpha.22

3 years ago

0.5.29-hotfix.0

3 years ago

0.5.33-alpha.25

3 years ago

0.5.33-alpha.24

3 years ago

0.5.30-alpha.0

4 years ago

0.5.30-alpha.2

4 years ago

0.5.30-alpha.1

4 years ago

0.5.30-alpha.4

3 years ago

0.5.30-alpha.3

3 years ago

0.5.30-alpha.6

3 years ago

0.5.30-alpha.5

3 years ago

0.5.30-alpha.8

3 years ago

0.5.30-alpha.7

3 years ago

0.5.32

3 years ago

0.5.33

3 years ago

0.5.30

3 years ago

0.5.31

3 years ago

0.5.33-alpha.3

3 years ago

0.5.38

3 years ago

0.5.33-alpha.4

3 years ago

0.5.33-alpha.5

3 years ago

0.5.36

3 years ago

0.5.37

3 years ago

0.5.34

3 years ago

0.5.33-alpha.0

3 years ago

0.5.35

3 years ago

0.5.33-alpha.1

3 years ago

0.5.33-alpha.6

3 years ago

0.5.33-alpha.7

3 years ago

0.5.33-alpha.8

3 years ago

0.5.29

4 years ago

0.5.10

4 years ago

0.5.11

4 years ago

0.5.18

4 years ago

0.5.19

4 years ago

0.5.16

4 years ago

0.5.17

4 years ago

0.5.14

4 years ago

0.5.12

4 years ago

0.5.13

4 years ago

0.5.20-alpha.0

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.6

4 years ago

0.5.5

4 years ago

0.5.0

4 years ago

0.3.2

4 years ago

0.5.2

4 years ago

0.3.4

4 years ago

0.5.1

4 years ago

0.5.8

4 years ago

0.5.9

4 years ago

0.5.21

4 years ago

0.5.22

4 years ago

0.5.27

4 years ago

0.5.28

4 years ago

0.5.25

4 years ago

0.5.26

4 years ago

0.5.23

4 years ago

0.5.24

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.5.21-alpha.0

4 years ago

0.4.2

4 years ago

0.3.0

4 years ago

0.1.1

4 years ago

0.3.1

4 years ago

0.0.95

4 years ago

0.0.96

4 years ago

0.0.98

4 years ago

0.0.99

4 years ago

0.0.101

4 years ago

0.0.100

4 years ago

0.0.93

4 years ago

0.0.94

4 years ago

0.1.0

4 years ago

0.0.87

4 years ago

0.0.88

4 years ago

0.0.89

4 years ago

0.0.90

4 years ago

0.0.91

4 years ago

0.0.92

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago