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',
|
|
|
|
};
|
|
|
|
|
2024-03-20 16:30:27 -05:00
|
|
|
const getContractAddressByNetworkName = (networkName, contractName) => {
|
2024-03-17 11:48:05 -05:00
|
|
|
const address = contractAddresses[networkName][contractName];
|
|
|
|
if (!address) throw new Error(`Contract ${contractName} not recognized`);
|
|
|
|
return address;
|
|
|
|
};
|
|
|
|
|
2024-03-20 16:30:27 -05:00
|
|
|
const getContractAddressByChainId = (chainId, contractName) => {
|
2024-03-17 11:48:05 -05:00
|
|
|
const network = Object.entries(networks).find(([, id]) => id === chainId)[0];
|
|
|
|
if (!network) throw new Error(`Chain ID ${chainId} not recognized`);
|
2024-03-20 16:30:27 -05:00
|
|
|
return getContractAddressByNetworkName(network, contractName);
|
2024-03-17 11:48:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
2024-03-20 16:30:27 -05:00
|
|
|
getContractAddressByChainId,
|
|
|
|
getContractAddressByNetworkName,
|
2024-03-17 11:48:05 -05:00
|
|
|
};
|