JSPM

@bosonprotocol/core-sdk

1.12.7-alpha.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 156
  • Score
    100M100P100Q113403F
  • License Apache-2.0

> TODO: description

Package Exports

  • @bosonprotocol/core-sdk
  • @bosonprotocol/core-sdk/dist/cjs/index.js
  • @bosonprotocol/core-sdk/dist/esm/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@bosonprotocol/core-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@bosonprotocol/core-sdk

JS lib that facilitates interaction with the Boson Protocol contracts, subgraph and metadata storage.

Install

The core-sdk is intended to be used in combination with implementations of the Web3LibAdapter and MetadataStorage interfaces.

If you, for example, want to use the core-sdk in combination with ethers and IPFS as the metadata storage, then run

npm i @bosonprotocol/core-sdk @bosonprotocol/ethers-sdk @bosonprotocol/ipfs-storage ethers

# OR

yarn add @bosonprotocol/core-sdk @bosonprotocol/ethers-sdk @bosonprotocol/ipfs-storage ethers

We currently support the following

Usage

The following assumes the usage of the core-sdk with ethers and IPFS as the metadata storage.

Initialize

Explicit

The core-sdk can be initialized by explicitly passing in the required arguments

import { CoreSDK } from "@bosonprotocol/core-sdk";
import { EthersAdapter } from "@bosonprotocol/ethers-sdk";
import { IpfsMetadata } from "@bosonprotocol/ipfs-storage";
import { ethers } from "ethers";

// injected web3 provider
const web3Provider = new ethers.providers.Web3Provider(window.ethereum);

// initialize explicitly
const coreSDK = new CoreSDK({
  web3Lib: new EthersAdapter(web3Provider),
  subgraphUrl: "https://api.thegraph.com/subgraphs/name/bosonprotocol/cc",
  protocolDiamond: "0x5E3f5127e320aD0C38a21970E327eefEf12561E5",
  // optional
  metadataStorage: new IpfsMetadata({
    url: "https://ipfs.infura.io:5001"
  }),
  // optional
  theGraphStorage: new IpfsMetadata({
    url: "https://api.thegraph.com/ipfs/api/v0"
  })
});

Default configuration

It is also possible to use the default configuration provided through the @bosonprotocol/common package.

import { CoreSDK } from "@bosonprotocol/core-sdk";
import { EthersAdapter } from "@bosonprotocol/ethers-sdk";
import { IpfsMetadata } from "@bosonprotocol/ipfs-storage";
import { ethers } from "ethers";

// injected web3 provider
const web3Provider = new ethers.providers.Web3Provider(window.ethereum);

// initialize via default config of chainId = 3
const coreSDK = CoreSDK.fromDefaultConfig({
  web3Lib: new EthersAdapter(web3Provider),
  chainId: 3
  // ...other args
});

Metadata

For handling metadata through the core-sdk, make sure to pass an instance as a constructor argument

import { CoreSDK } from "@bosonprotocol/core-sdk";
import { IpfsMetadata } from "@bosonprotocol/ipfs-storage";

const ipfsMetadata = new IpfsMetadata({ url: "https://ipfs.infura.io:5001" });
const coreSDK = CoreSDK.fromDefaultConfig({
  // ...other args
  metadataStorage: ipfsMetadata
});

// store metadata
const cid = await coreSDK.storeMetadata(offerMetadata);

// get metadata
await coreSDK.getMetadata(cid);

Offers

TODO

Exchange token

TODO