2024-03-17 13:35:51 -05:00
|
|
|
const contractAddresses = require('../contract-addresses.json');
|
2024-03-17 11:48:05 -05:00
|
|
|
|
|
|
|
const networks = {
|
|
|
|
localhost: '0x539',
|
|
|
|
sepolia: '0xaa36a7',
|
|
|
|
};
|
|
|
|
|
|
|
|
const getContractByNetworkName = (networkName, contractName) => {
|
|
|
|
const address = contractAddresses[networkName][contractName];
|
|
|
|
if (!address) throw new Error(`Contract ${contractName} not recognized`);
|
|
|
|
return address;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getContractByChainId = (chainId, contractName) => {
|
|
|
|
const network = Object.entries(networks).find(([, id]) => id === chainId)[0];
|
|
|
|
if (!network) throw new Error(`Chain ID ${chainId} not recognized`);
|
|
|
|
return getContractByNetworkName(network, contractName);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getContractByChainId,
|
|
|
|
getContractByNetworkName,
|
|
|
|
};
|