Skip to content

Instantly share code, notes, and snippets.

@nenadjaja
Created August 6, 2021 20:31
Show Gist options
  • Save nenadjaja/85719cb23be4b1e03d0e5055ce9e4f4e to your computer and use it in GitHub Desktop.
Save nenadjaja/85719cb23be4b1e03d0e5055ce9e4f4e to your computer and use it in GitHub Desktop.
// Ethereum account of the subgraph owner
const ethereumAccount = 0xbeb123....
// you need to upload the version metadata object to IPFS
const versionData = {
label: "v0.0.1",
description: "can be empty"
}
// IPFS Qm hash of the file with version metadata
const versionHash = uploadToIpfs(versionData)
// you need to upload subgraph metadata object to IPFS
const subgraphData = {
description: "My cool subgraph",
image: "https://images/myimage.png",
displayName: "Cool subgraph",
codeRepository: "can be empty",
website: "can be empty"
}
// IPFS Qm hash of the file with subgraph metadata
const subgraphHash = uploadToIpfs(subgraphData)
// Contract function to call
contractGNS.publishNewSubgraph(
ethereumAccount,
ipfsHexHash(version.deploymentId),
ipfsHexHash(versionHash),
ipfsHexHash(subgraphHash)
)
// ipfsHexHash is a helper that converts IPFS Qm.. hash into 0x123
export const ipfsHexHash = (ipfsHash: string) => {
const base58 = base('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')
return '0x' + base58.decode(ipfsHash).slice(2).toString('hex')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment