-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-erc1155.js
75 lines (63 loc) · 2.12 KB
/
generate-erc1155.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
const fs = require('fs')
const path = require('path')
const ora = require('ora')
const term = require('terminal-kit').terminal
const ethers = require('ethers')
const fastcsv = require('fast-csv')
const LinkdropSDK = require('@linkdrop/sdk').default
const config = require('./config')
;(async () => {
let spinner
try {
spinner = ora({
text: term.bold.green.str('Generating links'),
color: 'green'
})
spinner.start()
const linkdropSDK = new LinkdropSDK({
linkdropMasterAddress: config.LINKDROP_MASTER_ADDRESS,
factoryAddress: config.FACTORY_ADDRESS || '0xBa051891B752ecE3670671812486fe8dd34CC1c8',
chain: config.CHAIN || 'mainnet',
claimHost: config.CLAIM_HOST,
jsonRpcUrl: config.JSON_RPC_URL,
apiHost: config.API_HOST
})
const proxyAddress = linkdropSDK.getProxyAddress(config.CAMPAIGN_ID)
// Generate links
const links = []
const tokenIds = JSON.parse(decodeURI(config.TOKEN_IDS))
for (let i = 0; i < config.LINKS_NUMBER; i++) {
const {
url
} = await linkdropSDK.generateLinkERC1155({
signingKeyOrWallet: config.SIGNING_KEY,
weiAmount: config.WEI_AMOUNT || 0,
nftAddress: config.TOKEN_ADDRESS || ethers.constants.AddressZero,
tokenAmount: config.TOKENS_AMOUNT || 0,
expirationTime: config.EXPIRATION_TIME || 10000000000,
campaignId: config.CAMPAIGN_ID || 1,
wallet: config.DEFAULT_WALLET,
tokenId: tokenIds[i]
})
const finalUrl = config.MANUAL === "true" ? `${url}&manual=true` : url
links.push({ url: finalUrl })
}
// Save links
const dir = path.join(__dirname, './output')
const filename = path.join(dir, 'linkdrop.csv')
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
const ws = fs.createWriteStream(filename)
fastcsv.write(links).pipe(ws)
} catch (err) {
throw new Error(err)
}
spinner.succeed(term.bold.str(`Saved generated links to ^_${filename}`))
return links
} catch (err) {
spinner.fail(term.bold.red.str('Failed to generate links'))
throw new Error(err)
}
})()