-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
165 lines (152 loc) · 5.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require('dotenv').config()
const { JsonRpc, Api, JsSignatureProvider } = require('@proton/js')
const fetch = require('node-fetch')
// Constants
const ENDPOINT = 'https://proton.eoscafeblock.com'
const CREATOR = 'monsters'
const CREATOR_PERMISSION = 'active'
const COLLECTION_NAME = 'monsters'
const SCHEMA_NAME = 'monsters'
const CREATOR_FEE = 0.01
const SCHEMA = {
series: "uint16",
image: "string",
name: "string"
}
// NOTE: template_id must be manually inputted after `createTemplates()` is called, check proton.bloks.io
const templates = [
{ template_id: 1, max_supply: 100, series: 1, name: 'Dullahan', image: 'QmT35anF2vLjjfgCQXBXfXqGgXXj4rJrsjcXWYLm9HDfWL' },
{ template_id: 2, max_supply: 200, series: 1, name: 'Minotaur', image: 'Qmd3fNhjZGqKrLjLKNrRue7WqfNErnqgovrVFmS6xCumY6' },
{ template_id: 3, max_supply: 300, series: 1, name: 'Jersey Devil', image: 'QmXM5JC5jhmKNZEfQRazAfEksWmN6YEUDizCWsoGAD1isk' },
{ template_id: 4, max_supply: 400, series: 1, name: 'Misthag', image: 'QmeMzdUpyjPtBpZYgBnxApWETh4Cuo3HavUL63RzAwRcqT' },
{ template_id: 5, max_supply: 500, series: 1, name: 'Draugr', image: 'QmTpSH94BkNJCf82R1WFdPo6NcaiCZJmUdxCgGM2ka2Eue' },
{ template_id: 6, max_supply: 600, series: 1, name: 'Cropsey', image: 'QmPfkthP29F3a4RauRSZnGuMy4QV7bKfS4fvdkUTvGL7Hi' },
{ template_id: 7, max_supply: 700, series: 1, name: 'Typhon', image: 'QmYKrwqVbZAAHjT2BMhzeuFboSybKU7tNGFNgVj15CBy3F' },
{ template_id: 8, max_supply: 800, series: 1, name: 'Ghoul', image: 'QmXniR5MRo7QXG3Eb64jDpz5jyLw14796aAH8A19koHmez' },
{ template_id: 9, max_supply: 900, series: 1, name: 'Wendigo', image: 'QmbaX33qayCBmVqY3xaEX951DgG4nK1osN2RLtetvUdgPi' },
{ template_id: 10, max_supply: 1000, series: 1, name: 'Cerberus', image: 'QmejwojCLwjbNxqVNwBhyvKj5jUM4kGsm4tGM2U8CbniXy' },
]
// RPC
const rpc = new JsonRpc(ENDPOINT, { fetch })
const api = new Api({
rpc,
signatureProvider: new JsSignatureProvider([process.env.PRIVATE_KEY])
})
const transact = async (actions) => {
try {
await api.transact({ actions }, {
useLastIrreversible: true,
expireSeconds: 300
})
} catch (e) {
console.log(e)
}
}
const createCollection = async () => {
await transact([
{
"account": "atomicassets",
"name": "createcol",
"authorization": [{
"actor": CREATOR,
"permission": CREATOR_PERMISSION
}
],
"data": {
"author": CREATOR,
"collection_name": COLLECTION_NAME,
"allow_notify": true,
"authorized_accounts": [CREATOR],
"notify_accounts": [],
"market_fee": CREATOR_FEE,
"data": []
}
}
])
}
const createSchema = async () => {
await transact([
{
"account": "atomicassets",
"name": "createschema",
"authorization": [{
"actor": CREATOR,
"permission": CREATOR_PERMISSION,
}
],
"data": {
"authorized_creator": CREATOR,
"collection_name": CREATOR,
"schema_name": CREATOR,
"schema_format": Object.entries(SCHEMA).map(([key, type]) => ({
name: key,
type: type
}))
}
}
])
}
const createTemplates = async () => {
for (const template of templates) {
await transact([
{
"account": "atomicassets",
"name": "createtempl",
"authorization": [{
"actor": CREATOR,
"permission": CREATOR_PERMISSION
}
],
"data": {
"authorized_creator": CREATOR,
"collection_name": COLLECTION_NAME,
"schema_name": SCHEMA_NAME,
"transferable": true,
"burnable": true,
"max_supply": template.max_supply,
"immutable_data": Object.entries(SCHEMA).map(([key, type]) => ({
key: key,
value: [type, template[key]]
}))
}
}
])
}
}
const mintAssets = async () => {
const highToLowMint = templates.sort((t1, t2) => t2 - t1)
for (let i = 0; i < highToLowMint[0].max_supply; i++) {
for (const template of templates) {
if (i >= template.max_supply) {
continue;
}
await transact([
{
"account": "atomicassets",
"name": "mintasset",
"authorization": [{
"actor": CREATOR,
"permission": CREATOR_PERMISSION
}],
"data": {
"authorized_minter": CREATOR,
"collection_name": COLLECTION_NAME,
"schema_name": SCHEMA_NAME,
"template_id": template.template_id,
"new_asset_owner": CREATOR,
"immutable_data": [],
"mutable_data": [],
"tokens_to_back": []
}
}
])
}
}
}
const main = async () => {
await createCollection()
await createSchema()
await createTemplates()
await mintAssets()
}
main()