Skip to content

Instantly share code, notes, and snippets.

@PraneshASP
Created August 2, 2021 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PraneshASP/3f72eb906df2fec432d7558c39bc9a3b to your computer and use it in GitHub Desktop.
Save PraneshASP/3f72eb906df2fec432d7558c39bc9a3b to your computer and use it in GitHub Desktop.
Used to create your channel on the EPNS
require("dotenv").config();
const Ipfs = require("nano-ipfs-store");
const ethers = require("ethers");
const epnsAbi = require("../abis/epnsAbi.json");
const daiAbi = require("../abis/daiAbi.json");
const { EPNS_PROXY_ADDRESS, PROVIDER } = require("../constants");
async function createChannel() {
const channelName = "News Channel";
const channelInfo =
"This channel sends you the latest news on blockchain and cryptocurrency every 30 minutes";
const channelURL = "https://medium.com";
const channelFile = <CHANNEL_IMAGE>
const input = JSON.stringify({
name: channelName,
info: channelInfo,
url: channelURL,
icon: channelFile,
});
const ipfs = Ipfs.at("https://ipfs.infura.io:5001");
const storagePointer = await ipfs.add(input);
const MOCK_DAI = "0xf80A32A835F79D7787E8a8ee5721D0fEaFd78108";
const MOCK_DAI_ABI = daiAbi;
const EPNS_CONTRACT_ABI = epnsAbi;
const EPNS_CONTRACT_ADDR = EPNS_PROXY_ADDRESS;
const fees = ethers.utils.parseUnits(String(50));
const userPK = process.env.PRIVATE_KEY;
const wallet = new ethers.Wallet(userPK, PROVIDER);
const EPNS_CONTRACT = new ethers.Contract(
EPNS_CONTRACT_ADDR,
EPNS_CONTRACT_ABI,
wallet
);
const DAI_CONTRACT = new ethers.Contract(MOCK_DAI, MOCK_DAI_ABI, wallet);
epnsContractWithSigner = EPNS_CONTRACT.connect(wallet);
daiContractWithSigner = DAI_CONTRACT.connect(wallet);
const channelType = 2; // Open Channel
const identity = "1+" + storagePointer; // IPFS Storage Type and HASH
const identityBytes = ethers.utils.toUtf8Bytes(identity);
// Approve the DAI to stake
let tx = await daiContractWithSigner.approve(EPNS_CONTRACT_ADDR, fees);
// Wait till the transaction completes
await tx.wait();
//Create the Channel
const txs = await epnsContractWithSigner.createChannelWithFees(
channelType,
identityBytes,
{ gasPrice: 100000000000, gasLimit: 8000000 }
);
console.log(txs);
}
createChannel();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment