git clone https://github.com/bhavesh-ram/media-node-module.git
cd media-node-moduleRun the following command
npm installnpx hardhatChoose "Create a basic sample project" and follow the prompts.
npx hardhat compileIn a separate terminal, start Hardhat's local node:
npx hardhat nodeCreate a deploy script in the scripts/ directory, e.g., deploy.js (already present)
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
const MediaNode = await hre.ethers.getContractFactory("MediaNode");
const mediaNode = await MediaNode.deploy();
await mediaNode.waitForDeployment();
console.log("MediaNode deployed to:", mediaNode.address);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});Run the deploy script:
npx hardhat run scripts/deploy.js --network localhostYou can use the Hardhat console:
npx hardhat console --network localhostExample interaction:
const hre = require("hardhat");
const [owner] = await hre.ethers.getSigners();
const MediaNode = await hre.ethers.getContractFactory("MediaNode");
const mediaNode = await MediaNode.attach("<deployed_contract_address>");
// Register a node
await mediaNode.registerMediaNode({
id: "node1",
price_per_hour: 100,
name: "Node Name",
description: "Node Description",
url: "http://example.com",
cpu: 4,
ram_in_gb: 16,
storage_in_gb: 256
}, { value: 10 });