Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

642
Vistas
Error: You must provide the json interface of the contract when instantiating a contract object, abi undefined
const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');

const { abi, evm } = require('./compile');
console.log('abi',abi);

provider = new HDWalletProvider(
  'repeat place announce visit level double connect forest lens casual marble ladder',
  'https://mainnet.infura.io/v3/6f9868010c6948b2acd01733b944fcac'
);

const web3 = new Web3(provider);

const deploy = async () => {
  const accounts = await web3.eth.getAccounts();

  console.log('Attempting to deploy from account', accounts[0]);

  const result = await new web3.eth.Contract(abi)
    .deploy({ data: evm.bytecode.object})
    .send({ gas: '1000000', from: accounts[0] });

  console.log('Contract deployed to', result.options.address);
  provider.engine.stop();
};
deploy();

Compile.js

const path = require('path');
const fs = require('fs');
const solcCompile.js = require('solc');

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

var input = {
    language: 'Solidity',
    sources: {
      'Lottery.sol': {
        content: source
      }
    },
    settings: {
      outputSelection: {
        '*': {
          '*': ['*']
        }
      }
    }
  };
  
  var output = JSON.parse(solc.compile(JSON.stringify(input)));
  console.log("THe output", output);
  var contract = output.contracts['Lottery.sol'].Lottery;
  //console.log("Contract", contract)
  var bytecode = contract.evm.bytecode.object;
  var interface = contract.abi;
  module.exports = {interface, bytecode};

I created this code and ran the node deploy.js command and it gave me this error "Error: You must provide the JSON interface of the contract when instantiating a contract object."

And it shows me abi undefined I didn't understand me how to solve this error.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

abi is a json file so you need to add the assertion type when requesting or importing it

 import { abi, evm } from "url" assert { type: "json" };

to use require take a look at this https://andersonmmi.medium.com/using-require-to-import-abi-data-into-web3-eth-contract-a84d4a5b3cc3

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda