contracts/scripts/helpers/update_local_networkid.js
Sebastian Kippe adb7122a28
Add helper script for updating local address file
Can be run after starting the devchain, so that all local truffle
scripts work with the new network ID.
2019-04-02 17:35:28 +02:00

23 lines
777 B
JavaScript

const fs = require('fs');
const getNetworkId = require('./networkid.js');
module.exports = async function(callback) {
const daoAddressPath = 'lib/addresses/dao.json';
// TODO maybe do the same for KreditsKit address file
try {
const networkId = await getNetworkId(web3);
const daoAddresses = JSON.parse(fs.readFileSync(daoAddressPath));
const oldNetworkId = Math.max(...Object.keys(daoAddresses).map(a => parseInt(a)));
const localDaoAddress = daoAddresses[oldNetworkId];
daoAddresses[networkId] = localDaoAddress;
delete daoAddresses[oldNetworkId];
fs.writeFileSync(daoAddressPath, JSON.stringify(daoAddresses, null, 2));
console.log('Updated local network ID for DAO address');
} catch(e) {
console.log(e);
}
callback();
};