Last active
July 29, 2021 15:44
-
-
Save drewstaylor/45d5d2cb538adc2031df5c78a4ab6fda to your computer and use it in GitHub Desktop.
Change IPFS Provider in Taquito 9.2
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
{ | |
"name": "ipfs-gateway-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "fa2.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node tzipIpfsProvider.js" | |
}, | |
"keywords": [ | |
"Tezos" | |
], | |
"author": "[email protected]", | |
"license": "MIT", | |
"dependencies": { | |
"@taquito/beacon-wallet": "^9.2.0", | |
"@taquito/signer": "^9.2.0", | |
"@taquito/taquito": "^9.2.0", | |
"@taquito/tzip12": "^9.2.0", | |
"@taquito/tzip16": "^9.2.0" | |
} | |
} |
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
const TezosToolkit = require('@taquito/taquito') | |
const compose = require('@taquito/taquito'); | |
const tzip12 = require('@taquito/tzip12'); | |
const Tzip12Module = require('@taquito/tzip12'); | |
const tzip16 = require('@taquito/tzip16'); | |
const Tzip16Module = require('@taquito/tzip16'); | |
const importKey = require('@taquito/signer').importKey; | |
const Tezos = new TezosToolkit.TezosToolkit("https://mainnet-tezos.giganode.io"); | |
Tezos.addExtension(new Tzip12Module.Tzip12Module()); | |
Tezos.addExtension(new Tzip16Module.Tzip16Module()); | |
const FA2 = "KT1SFDJHTVMnfvc72E4vUt4Rpy9xvGKt1xSw"; | |
const getFa2 = async () => { | |
tzip16.IpfsHttpHandler('https://ipfs.infura.io'); | |
//tzip16.IpfsHttpHandler('https://cloudflare-ipfs.com'); | |
return Tezos.contract.at(FA2, compose.compose(tzip16.tzip16, tzip12.tzip12)); | |
}; | |
const main = async () => { | |
// Import Alice's key so you have a signer | |
await importKey(Tezos, 'edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq'); | |
// Load contract, storage and modules | |
const c = await getFa2(); | |
const storage = await c.storage(); | |
const m12 = await c.tzip12().getTokenMetadata(2); | |
const m16 = await c.tzip16().getMetadata(); | |
// Parse contract level storage | |
let m = {}; | |
let metadata = await storage.assets.token_metadata.get('2'); | |
let entries = metadata.token_info.entries(); | |
for (let entry of entries) { | |
if (entry[0] == 'attributes') { | |
let attributes = Buffer.from(entry[1], "hex").toString(); | |
m[entry[0]] = JSON.parse(attributes); | |
} else { | |
m[entry[0]] = Buffer.from(entry[1], "hex").toString(); | |
} | |
} | |
// All metadata | |
let meta = { | |
contract: m, | |
tzip12: m12, | |
tzip16: m16 | |
}; | |
// Look for `handlers: 'https://ipfs.infura.io'` property of `tzip16Module` to be updated | |
console.log('Result =>', {contract: c, tzip16Module: tzip16, metadata: meta}); | |
// Just Tzip16 metadata (with changed IPFS provider) | |
console.log(m16['metadata']); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment