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

media-sdk

v6.1.0

Published

The Media SDK is a comprehensive toolkit designed for seamless interaction with the Media Protocol's contracts. Developed in JavaScript, it harnesses the power of the [viem](https://viem.sh/) library, providing an intuitive interface for engaging with the

Downloads

256

Readme

Media SDK 🚀

The Media SDK is a comprehensive toolkit designed for seamless interaction with the Media Protocol's contracts. Developed in JavaScript, it harnesses the power of the viem library, providing an intuitive interface for engaging with the Media Protocol.

⚠️ Important Note: The contract addresses provided are currently from testnets and are subject to change. Always refer to the official documentation for the most up-to-date and valid contract addresses before any interactions.

📥 Installation

From GitHub

git clone [email protected]:mediafoundation/media-sdk.git
cd media-sdk
npm install

From NPM

npm install media-sdk

🛠️ Usage

Initializing the SDK

To initialize an instance of the Media SDK, use the Sdk class. This class constructor takes in an object with the following optional parameters:

  • chain: A chain object. See Viem's Chains for more details. If nothing is provided, the default chain will be used, which is Ethereum Goerli until mainnet launch.

  • transport: An array of transport objects. See Viem's Transport for more details.

  • privateKey: A ECP256K1 private key as a hex string to create a wallet client. Example: 'afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890'.

  • mnemonic: A BIP39 mnemonic phrase to create a wallet client. Example: 'degree tackle suggest window test behind mesh extra cover prepare oak script'.

  • walletClient: A wallet client. See Viem's Wallet Client for more details.

All parameters are optional. If all three privateKey, mnemonic, and walletClient are absent, only view functions will be available.

Examples

Using a private key. (Useful for backend applications)

import { Sdk, MarketplaceViewer, Marketplace, Resources, MarketplaceHelper } from 'media-sdk'

// initialize the sdk using a private key.
const sdk = new Sdk({ privateKey: 'afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890' })

Using a browser wallet:

import { Sdk, custom, createWalletClient, validChains } from 'media-sdk'

const [account] = await window.ethereum.request({method: 'eth_requestAccounts'})

const walletClient = createWalletClient({
    account: account,
    chain: validChains[Number(window.ethereum.chainId)],
    transport: [custom(window.ethereum)]
})

// initialize the SDK using a Viem walletClient. 
const sdk = new Sdk({ walletClient: walletClient });

Using it without signer just for view functions with a custom chain:

import { Sdk, MarketplaceViewer, validChains } from 'media-sdk'

const sdk = new Sdk({ chain: validChains[85432] })

const marketplaceViewer = new MarketplaceViewer(sdk)

const result = await marketplaceViewer.getPaginatedOffers({
  marketplaceId: 1, 
  start: 0, 
  count: 100
})
console.log(result)

Initializing a new Marketplace

Anybody can initialize a new marketplace. The marketplace will be initialized with the address of the caller as the owner. The owner can then transfer ownership to another address.

import { Sdk, MarketplaceStorage } from 'media-sdk'

// initialize the sdk using your mnemonic
const sdk = new Sdk({ mnemonic: 'degree tackle suggest window test behind mesh extra cover prepare oak script' })

// instanciate the marketplace contract
const marketplaceStorage = new MarketplaceStorage(sdk)

//initialize a new marketplace
const hash = await marketplaceStorage.initializeMarketplace({
  requiredStake: 10000000,  // marketplace min required staked liquidity 
  marketFeeTo: sdk.config.walletClient.account.address, // market fee recipient address 
  marketFeeRate: 5000, // market fee rate % (5000 = 0.5%)
  metadata: '{"name": "Test Marketplace"}',
})

// wait for the transaction to be mined
const transaction = sdk.config.publicClient.waitForTransactionReceipt( 
  { hash: hash }
)

//get the id of the new marketplace from the transaction logs
console.log(transaction.logs[0].topics[1])

Fetching Resources

// import the sdk
import { Sdk, Resources } from 'media-sdk'

// initialize the sdk using your mnemonic
const sdk = new Sdk()
const resources = new Resources(sdk)
const result = await resources.getPaginatedResources({
   userAddress: sdk.config.walletClient.account.address, 
   start: 0, 
   steps: 20 
})
console.log(result)

📚 More Information

For more details and a deep dive into our features, check out the official Media SDK documentation at https://www.mediaprotocol.net/sdk/overview.

Front-End Boilerplate

If you're looking for an example to get started with a front-end application, check out our Media Protocol Frontend Boilerplate. It's a great way to get started with the Media Protocol and the Media SDK.

📝 License

This project is licensed under the MIT License.

📢 Stay Connected!