-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
102 lines (88 loc) · 2.76 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
const ethers = require('ethers')
const inquirer = require('inquirer')
const fs = require('fs')
const _ = require('lodash')
// This file was used to deploy saturn20. Modify this file to create ERC20 wrappers
// for your own token. The "how to use" process is similar to that of
// https://github.com/saturn-network/etc-odyssey-audit
const provider = new ethers.providers.JsonRpcProvider(
'https://cloudflare-eth.com/', {
chainId: 1,
name: 'eth'
})
async function deploy(w) {
let wallet = w.connect(provider)
let contractinfo = JSON.parse(fs.readFileSync('./artifacts/ERC20Wrapper.json'))
let abi = contractinfo.compilerOutput.abi
let bytecode = contractinfo.compilerOutput.evm.bytecode.object
let factory = new ethers.ContractFactory(abi, bytecode, wallet)
let contract = await factory.deploy(
'0xb9440022a095343b440d590fcd2d7a3794bd76c8',
'Saturn DAO token (ERC20)',
'SATURN'
)
console.log(`Deploying Saturn20 (${contract.address}) to ETH mainnet; tx ${contract.deployTransaction.hash}`)
await contract.deployed()
console.log('Done')
}
function getWallet() {
let pkeyOrMnemonicPrompt = {
type: 'list',
name: 'usersecret',
message: 'How would you like to access your wallet?',
choices: ['Private Key', '12 Word Mnemonic']
}
inquirer.prompt(pkeyOrMnemonicPrompt).then(answers => {
if (answers.usersecret === 'Private Key') {
walletFromPkey()
} else {
walletFromMnemonic()
}
})
}
function walletFromPkey() {
let pkeyinput = {
type: 'password',
message: 'Enter your Private Key',
name: 'pkey'
}
inquirer.prompt(pkeyinput).then(async answers => {
try {
let wallet = new ethers.Wallet(answers.pkey)
await deploy(wallet)
} catch(e) {
console.error(`Unable to connect to Ethereum. Check that your private key is correct.`)
walletFromPkey()
}
})
}
function walletFromMnemonic() {
let mnemonicPrompt = {
type: 'password',
message: 'Enter your 12 Word Seed Phrase',
name: 'mnemonic'
}
inquirer.prompt(mnemonicPrompt).then(answers => {
let offsets = [...Array(10).keys()]
try {
let wallets = offsets.map(x => {
return ethers.Wallet.fromMnemonic(answers.mnemonic, `m/44'/60'/0'/0/${x}`)
})
let selectWalletPrompt = {
type: 'rawlist',
message: 'Select wallet:',
name: 'addy',
choices: wallets.map(x => x.address)
}
inquirer.prompt(selectWalletPrompt).then(async answers => {
let filtered = _.filter(wallets, x => x.address === answers.addy)
let wallet = filtered[0]
await deploy(wallet)
})
} catch(e) {
console.error(`Unable to connect to Ethereum. Check that your 12 word mnemonic is correct.`)
walletFromMnemonic()
}
})
}
getWallet()