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

BBW2019 #1

Open
wants to merge 14 commits into
base: master
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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ If you want to make a large batch of wallets and merge them into a single pdf fo

First, get your `template.html` looking right.

Then, edit `HOWMANY` in the `batch.js` and run it:
Then, edit `HOWMANY` in the `batch-austin.js` (original version from Austin Griffin) and run it:
```
node batch.js
node batch-austin.js
```
Also possible to generate without template (update background picture and sizes/positions of QR codes inside the script):
```
node batch-cannes.js
node batch.js
```

This will generate a file called `wallets.pdf` and also `addresses.txt` for airdropping.
Expand All @@ -50,9 +50,9 @@ Finally... print, fold, cut, and glue your way to freedom!

# sticker generation

It is possible to generate just QR code stickers instead of using templates. `batch-stickers.js` will generate them using template (`templatestickers*.html`) to place the stickers on page while `batch-stickers-cannes.js` (configured for Cannes film fetival demo) uses parameters configured inside the script to generate a page.
It is possible to generate just QR code stickers instead of using templates. `batch-stickers-tmpl.js` will generate them using template (`templatestickers*.html`) to place the stickers on page while `batch-stickers-gen.js` uses parameters configured inside the script to generate a page.

Configure `URL`, `HOWMANY`, `PATH` and `BATCH`. Additionaly `perPage` is configured in `batch-stickers.js` or `positions` in `batch-stickers-cannes.js`
Configure `URL`, `HOWMANY`, `PATH` and `BATCH`. Additionaly `perPage` is configured in `batch-stickers-tmpl.js` or `positions` in `batch-stickers-gen.js`

```
node batch-stickers.js
Expand All @@ -66,6 +66,9 @@ node batch-stickers-cannes.js

# air dropping

`airdrop.js` - For droping ERC20
`airdrop_nft.js` - For breeding NFTs using breeding conditions and distributing them

You will need a distribution account. I would suggest using a mnemonic you can remember in the Burner Wallet and then copy the private key the wallet generates.

You will then pass this private key into the airdrop script within the command you run it with or in a `.env` file:
Expand Down
22 changes: 12 additions & 10 deletions airdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ const fs = require("fs");
const { sendFunds, getBalance, sleep } = require ('./helpers');

const CONFIG = {
dryRun: true, //Tells you what it would do without actually sending any txs
provider: 'https://staging-testnet.leapdao.org/rpc',
dryRun: JSON.parse(process.env.DRY_RUN) || false, //Tells you what it would do without actually sending any txs
provider: 'https://testnet-node.leapdao.org',
dispenser: {
priv: process.env.SENDING_PK,
address: "0x"+ethereumjsutil.privateToAddress(process.env.SENDING_PK).toString('hex')
},
tokenColor: 1,
amountToSend: '2000000000000000000'
tokenColor: 3,
amountToSend: '3000000000000000000',
topUp: false //use this for adding funds to already funded wallets (account will not be checked if it has funds or not)
};
const folder = 'wallets';
const batch = '0';
const folder = 'wallets-ebt';
const batch = 'pa6';


//use this to debug CONFIG
Expand Down Expand Up @@ -49,7 +50,7 @@ async function main() {
for(let i = 0; i < accounts.length; i++) {
console.log(i, 'Dispensing', CONFIG.amountToSend, 'tokens to', accounts[i]);
balance = await getBalance(accounts[i], CONFIG.tokenColor, rpc);
if (String(balance) !== '0') {
if (!CONFIG.topUp && String(balance) !== '0') {
console.log(' Address already funded(', String(balance), '). Skipping.');
continue;
}
Expand All @@ -59,12 +60,13 @@ async function main() {
await sleep(1000);
txReceipt = await rpc.send("eth_getTransactionReceipt", [txHash]);
if(txReceipt) break;
}
}
const expectedBalance = CONFIG.topUp ? String(JSBI.add(balance, JSBI.BigInt(CONFIG.amountToSend))) : CONFIG.amountToSend;
balance = await getBalance(accounts[i], CONFIG.tokenColor, rpc);
if (String(balance) === CONFIG.amountToSend) {
if (String(balance) === expectedBalance) {
console.log(' Done');
} else {
console.log(' Failed! Expected balance:', CONFIG.amountToSend, 'actual: ', String(balance));
console.log(' Failed! Expected balance:', expectedBalance, 'actual: ', String(balance));
}
} else {
console.log(' Dry run mode enabled! Will not send tokens. Account balance:', String(balance));
Expand Down
93 changes: 93 additions & 0 deletions airdrop_nft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const Web3 = require('web3');
const JSBI = require('jsbi');
require('dotenv').config();
const ethereumjsutil = require("ethereumjs-util");
const ethers = require('ethers');
const fs = require("fs");
const { breed, getUtxos, getBreedCond, sleep } = require ('./helpers');

const NST_COLOR_BASE = 49153;
const CONFIG = {
dryRun: JSON.parse(process.env.DRY_RUN) || false, //Tells you what it would do without actually sending any txs
provider: 'https://testnet-node.leapdao.org',
dispenser: {
priv: process.env.SENDING_PK,
address: "0x"+ethereumjsutil.privateToAddress(process.env.SENDING_PK).toString('hex')
},
tokenColor: parseInt(process.env.COLOR) || NST_COLOR_BASE, //49155 - USB, 49156 - USA, 49160-65 - PA1-6
queenUtxoNum: parseInt(process.env.QUEEN_UTXO) || 0,
//queenId: '0xcbb18d83c09c99d8cfb5f0fad6febfb0d9a41fac9b165399982e43528e7c69db', //USB
//queenId: '0xa1f5da38474f60e5684a1e511e4668ff4f121c1bf4272cc129155fd2b88171a3', //USA
//queenId: '0x3e126cae83cf7524a4764e4ec95c35b1022727e5128afe8747c29883ca12c5cd', //PA1
//queenId: '0x3cea358b08c0001a4b45c561da6b0b3a7e3d6110898b400b9c4aea921ac9bf90', //PA2
//queenId: '0x4b76a985c779230d3ebc28ddb825677428816d3aa0c8173056326488130fcafd', //PA3
//queenId: '0x8b549686f1c520a969ac1aca76231cc96e6d7c1eee43c86b3c6a1e30223019ea', //PA4
//queenId: '0xa67c2236d8c9b88e8ff06197726eb62304bad3aba1e3dfaf5facd78810f2ef64', //PA5
queenId: '0x3516e6f1eca6e64e5d99315d9782953b2feeb50e0d1915ae4d10f44c8b03537f', //PA6
initData: "0x0000000000000000000000000000000000000000000000000000000000000000"
};
const folder = 'wallets-ebt';
const batch = 'pa6';


//use this to debug CONFIG
//console.log(CONFIG)
//process.exit(1)

const dispenserWallet = new ethers.Wallet(
CONFIG.dispenser.priv,
new ethers.providers.JsonRpcProvider(CONFIG.provider),
);

async function main() {
if(CONFIG.tokenColor < NST_COLOR_BASE) throw new Error(`Token color should be >= ${NST_COLOR_BASE}`);

let accounts = fs.readFileSync(`./${folder}/addresses-${batch}.txt`).toString().trim().split("\n");
const breedCond = (await getBreedCond(CONFIG.tokenColor, dispenserWallet.provider)).condAddr;
const condUtxos = await getUtxos(breedCond, CONFIG.tokenColor, dispenserWallet.provider);
let utxos;
let txHash;
let txReceipt;

console.log(accounts.length, 'NFTs will be bred and distributed');
console.log('Dispenser address:', CONFIG.dispenser.address);
console.log('Breeding condition address', breedCond);
console.log('Breeding condition UTXOs:', condUtxos);
if (CONFIG.dryRun) console.log('Dry run mode is enabled! No tokens will be dispensed!');
if(condUtxos.length == 0) {
if(!CONFIG.dryRun) {
throw new Error('Breeding condition does not have a queen!');
} else {
console.log('Breeding condition does not have a queen!');
}
}


for(let i = 0; i < accounts.length; i++) {
console.log(i, 'Breeding and sending NFT to', accounts[i]);
utxos = await getUtxos(accounts[i], CONFIG.tokenColor, dispenserWallet.provider);
if (utxos.length > 0) {
console.log(' Address already has tokens(', utxos.length, '). Skipping.');
continue;
}
txHash = await breed(accounts[i], CONFIG.queenId, CONFIG.queenUtxoNum, CONFIG.tokenColor, CONFIG.initData, dispenserWallet, CONFIG.dryRun);
if (!CONFIG.dryRun) {
for(let i = 0; i <= 5; i++) {
await sleep(1000);
txReceipt = await dispenserWallet.provider.send("eth_getTransactionReceipt", [txHash]);
if(txReceipt) break;
}
utxos = await getUtxos(accounts[i], CONFIG.tokenColor, dispenserWallet.provider);
if (utxos.length == 1) {
console.log(' Done');
} else {
console.log(' Failed! Expected 1 token, actual: ', utxos.length);
}
} else {
console.log(' Dry run mode enabled! Condition checked but not sent. Result:');
console.log(' ', txHash);
}
}
}

main();
37 changes: 37 additions & 0 deletions batch-austin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

const util = require('util');
const exec = util.promisify(require('child_process').exec);
var merge = require('easy-pdf-merge');
var fs = require('fs')

const HOWMANY = 5



async function generate() {

let sources = []

for(let count=1;count<=HOWMANY;count++){
const { stdout, stderr } = await exec('node index.js');
if (stderr) {
console.error(`error: ${stderr}`);
}
let name = stdout.substring(2,10)
console.log("Generated: "+name);
await exec('mv generated.pdf '+name+'.pdf');
sources[count-1] = (""+name+".pdf")
}
merge(sources,"wallets.pdf",function(err){
if(err)
return console.log(err);
console.log('Success');
var i = sources.length;
sources.forEach(function(filepath){
console.log("Cleaning up "+filepath)
fs.unlinkSync(filepath);
});
});

}
generate()
80 changes: 0 additions & 80 deletions batch-cannes.js

This file was deleted.

11 changes: 6 additions & 5 deletions batch-stickers-cannes.js → batch-stickers-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const asyncStickers = util.promisify(generateStickersHTML);
var merge = require('easy-pdf-merge');
var fs = require('fs');

const URL = "https://cannes.motion.ooo";
const HOWMANY = 100;
const PATH = 'wallets';
const BATCH = '0';
const URL = "https://planeta.leap.rocks";
const HOWMANY = 200;
const PATH = 'wallets-ebt';
const BATCH = 'pa1';
const SAVE_PK = true;
const workDir = process.cwd();
const positions = {
x:[50, 200, 350], //absolute X and Y positions for sticker elemnts on page
Expand All @@ -34,7 +35,7 @@ async function generate() {
const pages = Math.ceil(HOWMANY / perPage);

for (let i = 0; i < HOWMANY; i++) {
accounts.push(generateWallet(URL, `./${PATH}`,BATCH));
accounts.push(generateWallet(URL, `./${PATH}`,BATCH, SAVE_PK));
}
let pageAccounts;
let name;
Expand Down
File renamed without changes.
Loading