Не удалось найти ABI из ответа solc.compile web3.js

Я очень новичок в эфириуме и пытался получить байт-код и ABI из solc.compile с помощью web3js, но не смог найти ABI. Я получил байт-код. Я сохранил ответ json на файлы и смог получить только эти выходные данные.

  1. сборка.json
  2. байт-код.json
  3. развернутыйBytecode.json
  4. gasEstimates.json
  5. устаревшая сборка.json
  6. Идентификаторы методов.json

Вот мой код:

const inboxPath = path.resolve(__dirname,'contracts','inbox.sol');
const source = fs.readFileSync(inboxPath,'utf8');

// build path
const buildPath = path.resolve(__dirname, 'compiled');


/**
 * the new version only supports standard JSON in and out
 * @type {{settings: {outputSelection: {"*": {"*": string[]}}}, sources: {"inbox.sol": {content: string}}, language: string}}
 */
const input = {
    language: 'Solidity',
    sources: {
        'inbox.sol':{
            content: source,
        },
    },
    settings:{
        outputSelection: {
            '*': {
                '*': ['evm', 'bytecode'],
            },
        },
    },
};

async function compile() {
    const response = await solc.compile(JSON.stringify(input));

    const output = await JSON.parse(solc.compile(JSON.stringify(input)));

    const contracts = output.contracts['inbox.sol']["Inbox"].evm;

    const compiledResults = JSON.parse(response)["contracts"]["inbox.sol"]["Inbox"]["evm"];

    for (const contractName in contracts) {
        fs.writeFileSync(`${buildPath}/${contractName}.json`, JSON.stringify(contracts[contractName]))
    }
}

compile().then();

Вот версии web3js, Solidity и других необходимых пакетов, которые я использую:

  "dependencies": {
    "ganache-cli": "^6.12.2",
    "mocha": "^9.2.0",
    "solc": "^0.8.11",
    "web3": "^1.0.0-beta.26"
  }

Ответы (1)

Получил решение. Я забыл добавить abi к выбору вывода. Вот исправленная входная переменная.

const input = {
    language: 'Solidity',
    sources: {
        'inbox.sol':{
            content: source,
        },
    },
    settings:{
        outputSelection: {
            '*': {
                '*': ['evm', 'bytecode', 'abi'],
                // use * to get all the fields
                // '*': ["*"]
            },
        },
    },
};