I am using web3 v1.0.0-beta.37 and truffle contract for server.js configuration. I have defined two contracts FlightSuretyData.sol and FlightSuretyApp.sol FlightSuretyApp contract access functions from FlightSuretyData without importing the contract but through the FlightSuretyData deployed address. I have tried producing many steps through online research but I am not able to figure out the solution to this:

Here's my deploy_migrations:

const FlightSuretyApp = artifacts.require("../contracts/FlightSuretyApp.sol");
const FlightSuretyData = artifacts.require("../contracts/FlightSuretyData.sol");
const fs = require('fs');

module.exports = function(deployer) {

    let firstAirline = '0x55690752ed06B1d37510D20B3516b2D12F007f6d';

    deployer.deploy(FlightSuretyData, firstAirline)
    .then(() => {
        return deployer.deploy(FlightSuretyApp, FlightSuretyData.address)
                .then(() => {
                    let config = {
                        localhost: {
                            url: '',
                            dataAddress: FlightSuretyData.address,
                            appAddress: FlightSuretyApp.address,
                            numOracles: 50,
                    fs.writeFileSync(__dirname + '/../src/dapp/config.json',JSON.stringify(config, null, '\t'), 'utf-8');
                    fs.writeFileSync(__dirname + '/../src/server/config.json',JSON.stringify(config, null, '\t'), 'utf-8');

Here's my server.js configuration:

import FlightSuretyApp from '../../build/contracts/FlightSuretyApp.json';
import FlightSuretyData from '../../build/contracts/FlightSuretyData.json';
import contract from 'truffle-contract';
import Web3 from 'web3';
import express from 'express';
const bodyParser = require("body-parser");
const cors = require("cors");

let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
const accounts = web3.eth.getAccounts();
web3.eth.defaultAccount = "0x55690752ed06B1d37510D20B3516b2D12F007f6d";
let flightSuretyApp = contract(FlightSuretyApp, FlightSuretyApp.address);
let flightSuretyData = contract(FlightSuretyData, FlightSuretyData.address);

class ContractServer {

  constructor() {
    this.flightsForPurchase = [];
    this.flightsLanded = [];
    this.oracles = [];
    this.status = [20, 30, 40, 50, 0];

  init = async () => {

    flightSuretyApp.setProvider(new Web3.providers.HttpProvider('http://localhost:7545'));
    flightSuretyData.setProvider(new Web3.providers.HttpProvider('http://localhost:7545'));

    try {
      const address = await flightSuretyApp.address;
      const accs = await accounts;
      await flightSuretyData.methods.authorizeCaller(address).send({from: accs[0]});
    } catch (error) {
      console.error('Check if Ganache is running and contracts deployed properly!');

I have tried truffle migrate --reset --development

Here's the error produced:

Error: FlightSuretyApp has no network id set, cannot lookup artifact data. Either set the network manually using FlightSuretyApp.setNetwork(), run FlightSuretyApp.detectNetwork(), or use new(), at() or deployed() as a thenable which will detect the network automatically. Check if Ganache is running and contracts deployed properly!

  • what is the point of this code : flightSuretyApp.setProvider(new Web3.providers.HttpProvider('localhost:7545')); flightSuretyData.setProvider(new Web3.providers.HttpProvider('localhost:7545')); ? – Majd TL May 17 at 8:05
  • @MajdTL was just trying out set provider manually. 🤷‍♀️ – Sagar Atalatti May 17 at 12:01
  • how does your truffle config file look like? and why manually ? will await web3.flightSuretyData.me........ not work? – Majd TL May 17 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.