@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
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";
const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
const coreSDK = new CoreSDK({
web3Lib: new EthersAdapter(web3Provider),
subgraphUrl: "https://api.thegraph.com/subgraphs/name/bosonprotocol/cc",
protocolDiamond: "0x5E3f5127e320aD0C38a21970E327eefEf12561E5",
metadataStorage: new IpfsMetadata({
url: "https://ipfs.infura.io:5001"
}),
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";
const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
const coreSDK = CoreSDK.fromDefaultConfig({
web3Lib: new EthersAdapter(web3Provider),
chainId: 3
});
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({
metadataStorage: ipfsMetadata
});
const cid = await coreSDK.storeMetadata(offerMetadata);
await coreSDK.getMetadata(cid);
Offers
TODO
Exchange token
TODO