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

Migrations #2

Open
wants to merge 2 commits into
base: WKNCode
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
41 changes: 41 additions & 0 deletions 1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const token = artifacts.require('../contracts/WKNToken.sol')
const crowdsale = artifacts.require('../contracts/WKNCrowdsale.sol')
const setDefaultAccount = require('../scripts/setDefaultAccount.js')

module.exports = function(deployer, network, accounts) {
const rate = new web3.BigNumber(100)
const wallet = '0xa26b9eb1aedb38fe9536e871ecb7d40e0eb1b3b3'
// Setup default account
setDefaultAccount(web3)
const account = web3.eth.accounts.pop()
// Get gas limit
let gasLimit = web3.eth.getBlock('latest').gasLimit
let gasPrice = web3.eth.gasPrice
if (process.argv[4] === '--staging') {
gasPrice *= 4
}
console.log(`Determined gas limit: ${gasLimit}; and gas price: ${gasPrice}; max deployment price is ${web3.fromWei(gasPrice * gasLimit, 'ether')} ETH`)
// Deploy contract
return deployer
.then(() => {
return deployer.deploy(token, { gas: gasLimit, gasPrice: gasPrice, from: account })
})
.then(() => {
// Get gas limit
gasLimit = web3.eth.getBlock('latest').gasLimit
console.log(`Determined gas limit: ${gasLimit}; and gas price: ${gasPrice}; estimate max deployment price is ${web3.fromWei(gasPrice * gasLimit, 'ether')} ETH`)
console.log('This might take a while, please, be patient')
return deployer.deploy(
crowdsale,
token.address,
rate,
wallet,
{ gas: gasLimit, gasPrice: gasPrice, from: account },
)
})
.then(() => {
// Make smart-contract an owner
var tokenContract = web3.eth.contract(token.abi).at(token.address)
tokenContract.transferOwnership(crowdsale.address)
});
}
28 changes: 28 additions & 0 deletions createRealAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const request = require('sync-request')
const query = require('cli-interact').getYesNo

module.exports = function(callback) {
const account = web3.personal.newAccount('123456789')
console.log(`Created ETH wallet to deploy contracts: ${account} (password is '123456789', don't loose it) — you will be able to access it later`)
// Get gas limit
const gasLimit = web3.eth.getBlock('latest').gasLimit
const gasPrice = web3.eth.gasPrice
console.log(`Please, send at least ${web3.fromWei(gasPrice * gasLimit * 3, 'ether')}ETH to ${account} so that the contracts can be deployed`)
let funded = false
while(!funded) {
const answer = query(`Did you send ${web3.fromWei(gasPrice * gasLimit * 3, 'ether')} ETH to ${account}?`);
if (answer) {
console.log('Checking the balance...')
const balance = web3.eth.getBalance(account).toNumber()
if (balance >= gasPrice * gasLimit * 3) {
console.log(`ETH was received by ${account}, current balance is ${web3.fromWei(balance, 'ether')} ETH, proceeding to deploy the contracts...`)
funded = true
callback()
} else {
console.log(`Looks like Ethereum blockchain still does not have enough ETH (maybe transaction is not confirmed yet?). If you have sent enough ETH, it might be the case that you need to wait 10-15 minutes for the transaction to be synced. You can check the status of the transactions here: https://etherscan.io/address/${account} (current balance is current balance is ${web3.fromWei(balance, 'ether')} ETH)`)
}
} else {
console.log(`Please, send at least ${web3.fromWei(gasPrice * gasLimit * 3, 'ether')}ETH to ${account} so that the contracts can be deployed`)
}
}
}
28 changes: 28 additions & 0 deletions createTestAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const request = require('sync-request')

module.exports = function(callback) {
const account = web3.personal.newAccount('123456789')
console.log(`Created ETH wallet to deploy contracts: ${account} (password is '123456789', don't loose it)`)
console.log(`Requesting 1 ETH to ${account} (http://faucet.ropsten.be:3001/donate/${account})`)
const res = request('GET', `http://faucet.ropsten.be:3001/donate/${account}`)
if (res.statusCode >= 300) {
throw new Error('Sorry, Ethereum test faucet request failed: ' + res.body.toString())
}
console.log('Requested, waiting on the Ethereum node to sync and then 15 seconds to receive test ETH...')
setTimeout(() => {
checkBalance(account, callback)
}, 15 * 1000)
}

function checkBalance(account, callback) {
const balance = web3.eth.getBalance(account)
if (balance.toNumber() > 0) {
console.log(`Received 1 test ETH successfully (balance is ${web3.fromWei(balance, 'ether')} ETH)`)
callback()
} else {
console.log('Still waiting on 1 test ETH. Retrying to check balance in 15 seconds...')
setTimeout(() => {
checkBalance(account, callback)
}, 15 * 1000)
}
}
18 changes: 18 additions & 0 deletions setDefaultAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function(web3) {
if (process.argv[4] === '--staging') {
const account = web3.eth.accounts.pop()
console.log(`Setting default account to the last account at web3.eth.accounts and unlocking it: ${account}`)
web3.personal.unlockAccount(account, '123456789', 24 * 3600)
console.log(`${account} unlocked`)
web3.eth.defaultAccount = account
} else if (process.argv[4] === '--release') {
const account = web3.eth.accounts.pop()
console.log(`Setting default account to the last account at web3.eth.accounts and unlocking it: ${account}`)
web3.personal.unlockAccount(account, '123456789', 24 * 3600)
console.log(`${account} unlocked`)
web3.eth.defaultAccount = account
} else {
console.log(`Setting default account to the last account at web3.eth.accounts: ${web3.eth.accounts.pop()}`)
web3.eth.defaultAccount = web3.eth.accounts.pop()
}
}