Skip to content

pyra-marketplace/assets-sdk

Repository files navigation

Asset-SDK

npm version npm License

Overview

Asset-SDK provides an extensible set of methods and classes for encryption, unlocking, and monetization on the Dataverse file system network. With defining arbitrary file & asset linking graphs with smart contract gated access control, It should be a good start point for developers to understand and build their own asset marketplaces using new data infrastructures, including decentralized database, encrypted file system, decentralized key management system.

Install

Before installing asset-sdk, you should install @meteor-web3/connector, which is the entrance of Dataverse and Meteor.

pnpm install @meteor-web3/connector # if you haven't installed it yet
pnpm install @pyra-marketplace/assets-sdk

Examples

create token-file

import {
  Connector,
  MeteorWebProvider
} from "@meteor-web3/connector";
import {
  DEPLOYED_ADDRESSES as TOKEN_DEPLOYED_ADDRESSES,
  DataToken,
  ChainId
} from "@pyra-marketplace/assets-sdk";

const chainId = ChainId.BaseSepolia;
const connector = new Connector(new MeteorWebProvider());

const createTokenFile = async () => {
  const dataToken = new DataToken({
    chainId,
    connector
  });

  const date = new Date().toISOString();

  const res = await dataToken.createTokenFile({
    modelId: "DAPP_MODEL_ID",
    fileName: "create a file",
    fileContent: {
      modelVersion: "0.0.1",
      text: "hello",
      createdAt: date,
      updatedAt: date,
      encrypted: JSON.stringify({
        text: true
      })
    },
    actionsConfig: {
      collectAction: {
        currency: TOKEN_DEPLOYED_ADDRESSES[chainId].WETH,
        amount: 1000
      }
    },
  });
  const indexFileId = res.fileContent.file.fileId;
  console.log({ res, indexFileId });
};

collect token-file

import {
  Connector,
  MeteorWebProvider
} from "@meteor-web3/connector";
import {
  DataToken,
  DataAssetParser
} from "@pyra-marketplace/assets-sdk";

const connector = new Connector(new MeteorWebProvider());

const collectFile = async () => {
  const dataAssetParser = new DataAssetParser(connector);
  const dataAsset = await dataAssetParser.parse("DAPP_INDEX_FILE_ID");
  const dataToken = new DataToken({
    chainId: dataAsset.chainId,
    fileId: dataAsset.fileOrFolderId,
    assetId: dataAsset.assetId,
    connector
  });

  const collectionId = await dataToken.collect();
  console.log("DataToken collected, collectionId:", collectionId.toNumber());
};

You can find more asset-sdk usage in demo.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions to this project are welcome. To contribute, please follow these steps:

  1. Fork the repository and create a new branch.
  2. Make your changes and test them thoroughly.
  3. Submit a pull request with a detailed description of your changes.

About

Define arbitrary file & asset linking graphs with smart contract gated access control

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors