Last active
May 6, 2024 10:23
-
-
Save javiertc/1be22e9ce84bf2983066f1aecd891ac7 to your computer and use it in GitHub Desktop.
Import
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 axios = require('axios').default; | |
const TC_HOST = 'cardano-testnet-staging.tangocrypto.com'; | |
const TC_APP_ID = 'xxxxxxxxx'; | |
const TC_API_KEY = 'xxxxxxxxx'; | |
const NMKR_auth = 'xxxxxxxxxx'; | |
const NMKR_host = 'studio-api.testnet.nmkr.io'; | |
const NMKR_collection_id = '5d0c151f-03d7-4320-8252-096a3642c080' | |
const axiosTC = axios.create({ | |
baseURL: `https://${TC_HOST}/${TC_APP_ID}/v1`, | |
headers: { | |
'x-api-key': TC_API_KEY, | |
'Content-Type': 'application/json', | |
} | |
}); | |
const axiosNMKR = axios.create({ | |
baseURL: `https://${NMKR_host}/v2`, | |
headers: { | |
'Authorization': `Bearer ${NMKR_auth}`, | |
'Content-Type': 'application/json', | |
} | |
}); | |
const attributes = { | |
"Background": "<Background>", | |
"Suit": "<Suit>", | |
"Head": "<Head>", | |
"Mouth": "<Mouth>", | |
"Accessories": "<Accessories>", | |
"Eye": "<Eye>", | |
} | |
async function getNFTs(collection_id, page = 1, size = 50) { | |
try { | |
const response = await axiosNMKR.get(`/GetNfts/${collection_id}/all/${size}/${page}?orderby=id`); | |
return response.data; | |
} catch (error) { | |
console.error(error); | |
return []; | |
} | |
} | |
async function getNFTDetail(nft_uuid) { | |
try { | |
const response = await axiosNMKR.get(`/GetNftDetailsById/${nft_uuid}`); | |
return response.data; | |
} catch (error) { | |
console.error(error); | |
} | |
} | |
async function createTokens(collectionId, tokens) { | |
try { | |
const response = await axiosTC.post(`/nft/collections/${collectionId}/tokens`, JSON.stringify(tokens)); | |
console.log(response.data); | |
} catch (error) { | |
console.error(error); | |
} | |
} | |
async function main() { | |
const collectionId = '01gcc69761c697d8cv2b8sg4r6'; | |
// let collectionId = await createCollection(collection); | |
let page = 1; | |
const size = 50; | |
let nfts = [] | |
do { | |
console.log(`List NFTs page: ${page}, size: ${size}`); | |
nfts = await getNFTs(NMKR_collection_id, page, size); | |
page++; | |
for (let nft of nfts) { | |
// console.log(JSON.stringify(nft, null, 2)); | |
console.log("Get NFT Details:"); | |
let nftdetail = await getNFTDetail(nft.uid); | |
let metadata = JSON.parse(nftdetail.metadata); | |
// console.log(JSON.stringify(metadata, null, 2)); | |
const data = metadata['721'][nft.policyId][nft.name]; | |
console.log(JSON.stringify(data, null, 2)); | |
console.log('Image:', `ipfs://${nftdetail.ipfshash}`); | |
const tokensArr = { | |
"tokens": [{ | |
"asset_name": `${nftdetail.name}`, | |
"name": `${nftdetail.displayname}`, | |
// "description": `${data.description}`, | |
"image": `ipfs://${nftdetail.ipfshash}`, | |
"media_type": `${data.mediaType}`, | |
"metadata_attributes": Object.keys(data).filter(key => attributes[key]).map(key => ({ | |
"tag": attributes[key], | |
// "name": "Attribute color", | |
"value": data[key] | |
})) | |
}] | |
}; | |
console.log('TC payload:'); | |
console.log(JSON.stringify(tokensArr, null, 2)); | |
await createTokens(collectionId, tokensArr); | |
} | |
} while(nfts.length > 0) | |
console.log("DONE!"); | |
} | |
main(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment