Created
August 6, 2021 20:37
-
-
Save nenadjaja/5f3ef4bdb0412c5bd5de2a1aca1fa68e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ethereum account of the subgraph owner | |
const ethereumAccount = 0xbeb123.... | |
// Network subgraph number - you get it from the id | |
// if subgraphId is this: 0x87d11bd744b882b7bc5a6b5450cba8c35d90eb10-1 | |
// the networkSubgraphNumber will be the number after the dash, so here number 1 | |
const networkSubgraphNumber = subgraph.id.split('-')[1], | |
// 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) | |
// call GNS contract to publish a new version | |
contractGNS.publishNewVersion( | |
ethereumAccount, | |
networkSubgraphNumber, | |
ipfsHexHash(version.deploymentId), | |
ipfsHexHash(versionHash) | |
) | |
// 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