Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

638
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!