Тестовый коммит после удаления husky

This commit is contained in:
2025-03-05 01:02:09 +03:00
parent 97ca5e4b64
commit 3157ad0cd9
118 changed files with 8177 additions and 8530 deletions

View File

@@ -0,0 +1,46 @@
const { ethers } = require('ethers');
const fs = require('fs');
const path = require('path');
const logger = require('./logger');
/**
* Получает экземпляр контракта по его имени
* @param {string} contractName - Имя контракта (например, 'AccessToken')
* @returns {Promise<ethers.Contract>} - Экземпляр контракта
*/
async function getContract(contractName) {
try {
// Путь к артефакту контракта
const artifactPath = path.join(__dirname, '..', 'artifacts', 'contracts', `${contractName}.sol`, `${contractName}.json`);
// Проверка существования файла
if (!fs.existsSync(artifactPath)) {
throw new Error(`Артефакт контракта ${contractName} не найден по пути ${artifactPath}`);
}
// Загрузка ABI из артефакта
const contractArtifact = require(artifactPath);
const contractABI = contractArtifact.abi;
// Получение адреса контракта из переменных окружения
const contractAddress = process.env[`${contractName.toUpperCase()}_ADDRESS`];
if (!contractAddress) {
throw new Error(`Адрес контракта ${contractName} не найден в переменных окружения`);
}
// Подключение к провайдеру
const provider = new ethers.JsonRpcProvider(process.env.ETHEREUM_NETWORK_URL);
// Создание экземпляра контракта
const contract = new ethers.Contract(contractAddress, contractABI, provider);
return contract;
} catch (error) {
logger.error(`Ошибка при получении контракта ${contractName}: ${error.message}`);
throw error;
}
}
module.exports = {
getContract
};