2

I am new to the truffle framework. I have initialised my contract Dapp with the constructor function as given below

pragma solidity ^0.5.0;

contract Dapp {
    uint public totalSupply;

    constructor() public {
        totalSupply = 1000000;
    }
}

and my migrations file in regards with the contract is

const Dapp = artifacts.require("Dapp");

module.exports = function(deployer) {
  deployer.deploy(Dapp);
};

I have compiled and migrated using the command truffle compile and truffle migrate, which results in successful compilation.

But when accessing the contract in truffle console like

let instance = await Dapp.deployed()

It results in ReferenceError: Dapp is not defined, I cannot able to figure out what went wrong. Is there any possible solution to this. And yeah I have followed the latest Truffle documentaion.

Documentation link for migration and interacting with truffle console.

My Network is in development mode which is given below

networks: {
    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 7545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },
}
4
  • did you set the location to your private network right? you should check at here: truffleframework.com/docs/truffle/reference/configuration
    – haxerl
    Commented Mar 11, 2019 at 23:46
  • Yea I have added @haxerl Commented Mar 12, 2019 at 16:19
  • can you provide what private network did you use? and the command to create that network
    – haxerl
    Commented Mar 14, 2019 at 0:08
  • Yea, I have added it @haxerl Commented Mar 14, 2019 at 15:14

2 Answers 2

1

Okay change your port at truffle-config.js in the network section to 9545 for truffle develop environment. The reason why you can read at here: https://truffleframework.com/docs/truffle/getting-started/using-truffle-develop-and-the-console in the truffle develop section

This will spawn a development blockchain locally on port 9545, regardless of what your truffle-config.js configuration file calls for

5
  • I have tried that too, its not working Commented Mar 22, 2019 at 10:37
  • I think you should post this question on truffle github as an issue maybe they will help you better
    – haxerl
    Commented Mar 22, 2019 at 16:16
  • yea I will post this as an issue in truffle GitHub profile. Thanks for the response Commented Mar 23, 2019 at 16:25
  • sorry we cant do much
    – haxerl
    Commented Mar 23, 2019 at 16:47
  • It's okay, sir. I will try in GitHub. Commented Mar 23, 2019 at 16:53
0

Apologies for not being able to comment instead of adding a new answer. I wonder if you somehow migrated contracts to Ganache (or a testnet), then tried to access it in Truffle Develop blockchain.

Could you upload a minimal repo to Github so that we reproduce the issue?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.