-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (22 loc) · 843 Bytes
/
index.js
File metadata and controls
27 lines (22 loc) · 843 Bytes
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
const abi = require('./lib/abi.js');
const addresses = require('./lib/address.js');
module.exports = function (web3, opts = {}) {
let networkId = opts["networkId"] || web3.version.network;
let contracts = {};
Object.keys(addresses).forEach(function (contractName) {
let config = {
address: addresses[contractName][networkId],
abi: abi[contractName][networkId]
};
let contractOpts = opts[contractName];
['address', 'abi'].forEach(m => {
if (contractOpts && contractOpts[m]) {
config[m] = contractOpts[m];
}
});
if(!config.abi) { throw 'ABI not found for contract: ' + contractName; }
if(!config.address) { throw 'address not found for contract: ' + contractName;}
contracts[contractName] = web3.eth.contract(config.abi).at(config.address);
});
return contracts;
};