Skip to content

Commit

Permalink
Merge pull request #10 from LinkdropHQ/dev
Browse files Browse the repository at this point in the history
added fixes for standards + new sdk version
  • Loading branch information
Dobrokhvalov authored Jan 24, 2022
2 parents 36e54cf + e2c13f3 commit a070c8c
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 45 deletions.
13 changes: 0 additions & 13 deletions config/config.json.sample

This file was deleted.

75 changes: 75 additions & 0 deletions generate-erc1155.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
})()
13 changes: 6 additions & 7 deletions index.js → generate-erc20.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const config = require('./config')

const linkdropSDK = new LinkdropSDK({
linkdropMasterAddress: config.LINKDROP_MASTER_ADDRESS,
factoryAddress:
config.FACTORY_ADDRESS || '0xBa051891B752ecE3670671812486fe8dd34CC1c8',
chain: config.CHAIN || 'mainnet'
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)
Expand All @@ -30,10 +32,7 @@ const config = require('./config')

for (let i = 0; i < config.LINKS_NUMBER; i++) {
const {
url,
linkId,
linkKey,
linkdropSignerSignature
url
} = await linkdropSDK.generateLink({
signingKeyOrWallet: config.SIGNING_KEY,
weiAmount: config.WEI_AMOUNT || 0,
Expand Down
73 changes: 73 additions & 0 deletions generate-erc721.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.generateLinkERC721({
signingKeyOrWallet: config.SIGNING_KEY,
weiAmount: config.WEI_AMOUNT || 0,
expirationTime: config.EXPIRATION_TIME || 10000000000,
campaignId: config.CAMPAIGN_ID || 1,
wallet: config.DEFAULT_WALLET,
nftAddress: config.TOKEN_ADDRESS || ethers.constants.AddressZero,
tokenId: tokenIds[i]
})

links.push({ url })
}

// 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)
}
})()
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"author": "Amir Jumaniyazov <[email protected]>",
"license": "MIT",
"private": false,
"scripts": { "generate": "node index" },
"scripts": {
"generate-erc20": "node generate-erc20.js",
"generate-erc721": "node generate-erc721.js",
"generate-erc1155": "node generate-erc1155.js"
},
"dependencies": {
"@babel/runtime": "^7.7.7",
"@linkdrop/sdk": "^1.1.2",
"@linkdrop/sdk": "^1.2.0",
"ethers": "^4.0.41",
"fast-csv": "^4.0.1",
"ora": "^4.0.3",
Expand Down
Loading

0 comments on commit a070c8c

Please sign in to comment.