Nft minting works

This commit is contained in:
2022-01-23 01:18:18 +03:00
parent 11cf01c39d
commit 7f4c9bcd79
5 changed files with 1705 additions and 15176 deletions

9
README.md Normal file
View File

@@ -0,0 +1,9 @@
# vk-nft-feed
*Инструмент для создания коллекции NFT из постов сообщества или пользователя Вконтакте*
Использование:
1. Получить [сервисный ключ доступа]() и поместить его в .env файл.
2. `npm i`
3. `node index.js`

View File

@@ -1,15 +1,26 @@
import dotenv from 'dotenv';
dotenv.config();
import Rarepress from 'rarepress';
import Rareterm from 'rareterm.node';
import getImages from './getImages.js';
(async () => {
const rarepress = new Rarepress();
// await rarepress.init({ network: 'mainnet' });
const rarepress = new Rareterm();
await rarepress.init({ host: "https://rinkeby-beta.rarepress.org/v1" });
(await getImages(-1)).forEach((image) => {
console.log(image);
// const cid = await rarepress.fs.add()
(await getImages(-1)).forEach(async (image, index) => {
const cid = await rarepress.fs.add(Buffer.from(image));
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}`);
})
})();

16797
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,13 +5,15 @@
"main": "index.js",
"type": "module",
"scripts": {
"run": "node index.js"
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@svgdotjs/svg.js": "^3.1.1",
"axios": "^0.25.0",
"dotenv": "^14.2.0",
"rarepress": "^0.1.7"
"rareterm.node": "^0.0.10",
"svgdom": "^0.1.10"
}
}

View File

@@ -1,22 +1,22 @@
import {createSVGWindow} from 'svgdom';
import {SVG, registerWindow} from '@svgdotjs/svg.js';
function makeSvg(images) {
const spacing = 50;
const height = images.length * (900 + spacing) + spacing;
function imageTag(url, n) {
const y = 50 + n * (900 + spacing);
return `<image x="50" y="${y}" width="900" height="900" href="${url}"/>`;
}
let imageTags = '';
const window = createSVGWindow();
const document = window.document;
registerWindow(window, document);
const draw = SVG(document.documentElement).width(1000).height(height);
draw.rect(1000, height).fill('white');
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">
<rect width="100%" height="100%" fill="white" />
${imageTags}
</svg>\n`;
return draw.svg();
}
export default function(post) {
@@ -26,7 +26,7 @@ export default function(post) {
const images = photoAttachments.map((attachment) => {
return {
url: attachment.photo.sizes[attachment.photo.sizes.length - 1].url.replaceAll('&', '&amp;'),
url: attachment.photo.sizes[attachment.photo.sizes.length - 1].url,
};
});