Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mass drop scripts #46

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PINATA_API_KEY='your-pinata-api-key'
PINATA_SECRET_API_KEY='your-pinata-secret-api-key'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/*

.env
7 changes: 7 additions & 0 deletions data/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "CollectionName",
"metadata_base_uri": "ipfs",
"royalties_schedule": {
"entitlements": [[0, 5]]
}
}
13 changes: 13 additions & 0 deletions data/mass-drop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"price": 10,
"asset_id": 0,
"max_supply": 50,
"transaction_limit": 5,
"activation_time": 3000,
"pre_sale": {
"price": 5,
"transaction_limit": 1,
"activation_time": 2500,
"max_supply": 10
}
}
9 changes: 9 additions & 0 deletions data/mint-series.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"collection_id": 0,
"quantity": 0,
"owner_address": "OwnerAddress",
"attributes": [{ "Text": "temp-attribute" }],
"royalties_schedule": {
"entitlements": [[0, 5]]
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"license": "ISC",
"dependencies": {
"@cennznet/api": "1.5.0-alpha.4",
"@pinata/sdk": "^1.1.23",
"dotenv": "^10.0.0",
"minimist": "^1.2.5"
},
"resolutions": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-asset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Example create a new generic asset
let keys = new keyring.Keyring({'type': 'sr25519'});
let ownerAddress = '5FWEHQqYMN8YCg8yJxKHnon7Dtx4Psp2xnjvKfQqGC6kUwgv';
let ownerAddress = '5DVHuiWPrWomw1GxgXx6XuDCURPdDcv6YjLchobf156kwnZx';
let sudoKey = keys.addFromUri('//YourSudoKey');

// 1 million tokens with 18dp
Expand Down
49 changes: 49 additions & 0 deletions scripts/mass-drop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
dotenv.config();
const pinata = pinataSDK(
process.env.PINATA_API_KEY,
process.env.PINATA_SECRET_API_KEY
);
const keys = new keyring.Keyring({ type: "sr25519" });
const sudoKey = keys.addFromUri("//YourSudoKey");

// Create collection
// Edit fields in data/collection.json
let rawData = fs.readFileSync("./data/collection.json");
const collectionData = JSON.parse(rawData);

await api.tx.nft
.createCollection(
collectionData.name,
collectionData.metadata_base_uri,
collectionData.royalties_schedule
)
.signAndSend(sudoKey);

// Mass drop
// Edit fields in data/mint-series.json and data/mass-drop.json
rawData = fs.readFileSync("./data/mint-series.json");
const mintSeriesData = JSON.parse(rawData);

rawData = fs.readFileSync("./data/mass-drop.json");
const massDropData = JSON.parse(rawData);

const metadata = {
name: collectionData.name,
collectionId: mintSeriesData.collection_id,
ownerAddress: mintSeriesData.owner_address,
attributes: mintSeriesData.attributes,
};

const pin = await pinata.pinJSONToIPFS(metadata);

await api.tx.nft
.mintSeries(
mintSeriesData.collection_id,
mintSeriesData.quantity,
mintSeriesData.owner_address,
mintSeriesData.attributes,
pin.IpfsHash,
mintSeriesData.royalties_schedule,
{ ...massDropData }
)
.signAndSend(sudoKey);
27 changes: 15 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import minimist from 'minimist';
import {Api, WsProvider } from '@cennznet/api';
import { Api, WsProvider } from '@cennznet/api';
import repl from 'repl';
import fs from 'fs';
import keyring from '../node_modules/@polkadot/keyring/index.js';
import * as utilCrypto from '../node_modules/@polkadot/util-crypto/index.js';
import * as utils from '../node_modules/@polkadot/util/index.js';
import dotenv from 'dotenv';
import pinataSDK from '@pinata/sdk';

const args = minimist(process.argv.slice(2));

async function setup() {
let endpoint = 'ws://localhost:9944';
if (args.endpoint) {
if(args.endpoint === 'mainnet') {
if (args.endpoint === 'mainnet') {
args.endpoint = 'wss://cennznet.unfrastructure.io/public/ws';
} else if(args.endpoint === 'nikau') {
} else if (args.endpoint === 'nikau') {
args.endpoint = 'wss://nikau.centrality.me/public/ws';
}
endpoint = args.endpoint;
Expand All @@ -33,7 +35,7 @@ async function setup() {
// Setup API session
let provider = new WsProvider(endpoint, 10);
console.log(`connecting to: ${endpoint}...`);
global.api = await Api.create({ provider: endpoint, types })
global.api = await Api.create({ provider: endpoint, types });
console.log(`connected ✅`);

// Setup injected helper libs / functions
Expand All @@ -54,7 +56,9 @@ async function setup() {

async function main() {
if (args.run) {
console.log(`Running user script: '${args.run}' with: api, utilCrypto, keyring, utils`);
console.log(
`Running user script: '${args.run}' with: api, utilCrypto, keyring, utils`
);
let script = fs.readFileSync(args.run).toString();
eval(`(async () => {${script}})()`);
} else {
Expand All @@ -66,13 +70,12 @@ async function main() {

setup()
.then(() => {
main()
.catch(err => {
console.log(`error during execution: ${err}`)
process.exit(1);
});
main().catch((err) => {
console.log(`error during execution: ${err}`);
process.exit(1);
});
})
.catch(err => {
console.log(`error during setup: ${err}`)
.catch((err) => {
console.log(`error during setup: ${err}`);
process.exit(1);
});
22 changes: 22 additions & 0 deletions types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"PalletId": "u32",
"MarketplaceId": "u32",
"Marketplace": {
"account": "AccountId",
"entitlement": "Permill"
},
"MassDrop": {
"price": "Balance",
"assetId": "AssetId",
"maxSupply": "TokenCount",
"transactionLimit": "Option<TokenCount>",
"activationTime": "BlockNumber",
"preSale": "Option<Presale>"
},
"Presale": {
"price": "Balance",
"transactionLimit": "Option<TokenCount>",
"activationTime": "BlockNumber",
"maxSupply": "TokenCount"
}
}
Loading