mirror of
https://github.com/anatolykopyl/vk-nft-feed.git
synced 2026-03-26 12:54:33 +00:00
Nft minting works
This commit is contained in:
9
README.md
Normal file
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# vk-nft-feed
|
||||||
|
|
||||||
|
*Инструмент для создания коллекции NFT из постов сообщества или пользователя Вконтакте*
|
||||||
|
|
||||||
|
|
||||||
|
Использование:
|
||||||
|
1. Получить [сервисный ключ доступа]() и поместить его в .env файл.
|
||||||
|
2. `npm i`
|
||||||
|
3. `node index.js`
|
||||||
23
index.js
23
index.js
@@ -1,15 +1,26 @@
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
import Rarepress from 'rarepress';
|
import Rareterm from 'rareterm.node';
|
||||||
import getImages from './getImages.js';
|
import getImages from './getImages.js';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const rarepress = new Rarepress();
|
const rarepress = new Rareterm();
|
||||||
// await rarepress.init({ network: 'mainnet' });
|
await rarepress.init({ host: "https://rinkeby-beta.rarepress.org/v1" });
|
||||||
|
|
||||||
(await getImages(-1)).forEach((image) => {
|
(await getImages(-1)).forEach(async (image, index) => {
|
||||||
console.log(image);
|
const cid = await rarepress.fs.add(Buffer.from(image));
|
||||||
// const cid = await rarepress.fs.add()
|
const token = await rarepress.token.create({
|
||||||
|
type: "ERC721",
|
||||||
|
metadata: {
|
||||||
|
name: `${index}`,
|
||||||
|
description: `${index}.svg`,
|
||||||
|
image: `/ipfs/${cid}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await rarepress.fs.push(cid);
|
||||||
|
await rarepress.fs.push(token.uri);
|
||||||
|
const sent = await rarepress.token.send(token);
|
||||||
|
console.log(`[${index}] published: https://rarible.com/token/${sent.id}`);
|
||||||
})
|
})
|
||||||
})();
|
})();
|
||||||
|
|||||||
16817
package-lock.json
generated
16817
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,13 +5,15 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"run": "node index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@svgdotjs/svg.js": "^3.1.1",
|
||||||
"axios": "^0.25.0",
|
"axios": "^0.25.0",
|
||||||
"dotenv": "^14.2.0",
|
"dotenv": "^14.2.0",
|
||||||
"rarepress": "^0.1.7"
|
"rareterm.node": "^0.0.10",
|
||||||
|
"svgdom": "^0.1.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
post2Svg.js
26
post2Svg.js
@@ -1,22 +1,22 @@
|
|||||||
|
import {createSVGWindow} from 'svgdom';
|
||||||
|
import {SVG, registerWindow} from '@svgdotjs/svg.js';
|
||||||
|
|
||||||
function makeSvg(images) {
|
function makeSvg(images) {
|
||||||
const spacing = 50;
|
const spacing = 50;
|
||||||
const height = images.length * (900 + spacing) + spacing;
|
const height = images.length * (900 + spacing) + spacing;
|
||||||
|
|
||||||
function imageTag(url, n) {
|
const window = createSVGWindow();
|
||||||
const y = 50 + n * (900 + spacing);
|
const document = window.document;
|
||||||
return `<image x="50" y="${y}" width="900" height="900" href="${url}"/>`;
|
registerWindow(window, document);
|
||||||
}
|
|
||||||
|
|
||||||
let imageTags = '';
|
|
||||||
|
|
||||||
|
const draw = SVG(document.documentElement).width(1000).height(height);
|
||||||
|
draw.rect(1000, height).fill('white');
|
||||||
images.forEach((image, i) => {
|
images.forEach((image, i) => {
|
||||||
imageTags += imageTag(image.url, i);
|
const y = 50 + i * (900 + spacing);
|
||||||
})
|
draw.image(image.url).x(50).y(y).width(900).height(900)
|
||||||
|
});
|
||||||
|
|
||||||
return `<svg viewBox="0 0 1000 ${height}" xmlns="http://www.w3.org/2000/svg">
|
return draw.svg();
|
||||||
<rect width="100%" height="100%" fill="white" />
|
|
||||||
${imageTags}
|
|
||||||
</svg>\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(post) {
|
export default function(post) {
|
||||||
@@ -26,7 +26,7 @@ export default function(post) {
|
|||||||
|
|
||||||
const images = photoAttachments.map((attachment) => {
|
const images = photoAttachments.map((attachment) => {
|
||||||
return {
|
return {
|
||||||
url: attachment.photo.sizes[attachment.photo.sizes.length - 1].url.replaceAll('&', '&'),
|
url: attachment.photo.sizes[attachment.photo.sizes.length - 1].url,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user