Skip to main content

Initializing a Marketplace

The Marketplace contract is the core of the Media Protocol. It allows users to initialize new marketplaces, register as providers, create offers, take deals, and more. Through the SDK, users can make use of all the functions available in the contract in a Javascript enviroment. Click here to check the technical reference of the contract where you can find all the available functions.

Examples

Initialize a new marketplace

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

// initialize the sdk using your mnemonic (you can also use a privateKey or viem walletClient)
const sdk = new Sdk({ mnemonic: 'your mnemonic phrase' });

// instanciate the marketplace contract
const marketplace = new Marketplace(sdk);

// initialize a new marketplace
const hash = await marketplace.initializeMarketplace({
requiredStake: 100, // replace with your required stake
marketFeeTo: sdk.config.walletClient.account.address, // replace with your market fee recipient address
marketFeeRate: 50000, // replace with your market fee rate % ex 5% = 50000
metadata: '{"name": "Test Marketplace"}' // replace with your metadata
});

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

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

Get a specific offer from a marketplace

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

// initialize the sdk (defaults to goerli testnet)
const sdk = new Sdk();

// instanciate the marketplace contract
const marketplace = new Marketplace(sdk);

// [1,1] is the id of the marketplace and the offer
const offer = await marketplace.view("getOffer",[1, 1]);