How can I deploy a HelloWorld contract on my testrpc network

0 votes

Following is my helloworld.sol contract:

pragma solidity ^0.4.17;

contract HelloWorld{  
    function sayHello() internal pure returns(string){
        return("Hello 2018!");
    }
}

Initial migrations.js:

var Migrations = artifacts.require("./Migrations.sol");
var HelloWorld = artifacts.require("./HelloWorld.sol");

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

And since I'm using truffle, truffle.js:

module.exports = {

  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    }
  }

};

When I run commands:

truffle compile
truffle migrate
truffle console

I get 

Error: HelloWorld has not been deployed to detected network (network/artifact mismatch) at C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:317116:17 at at process._tickDomainCallback (internal/process/next_tick.js:228:7)

How do I correctly deploy my contract and test its method?

Apr 27, 2018 in Blockchain by Johnathon
• 9,090 points
2,882 views
Which Operating System are you using?
Hi @Killian, I am using Windows 7

1 answer to this question.

0 votes

The problem lies in the command:

truffle migrate

Your truffle migrate command is showing nothing was deployed. Your output should look something like this:

$ truffle migrate
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x92408ab65d6fb64dedcf1e3aaa99854cc5fc3eb3e15687e04df86d357cdf22d8
  Migrations: 0xbaae4238d6818704f09c253d4c7bc57a3585623a
  Deploying HelloWorld...
  ... 0x47d7237c07e819f28dd7e154cfef67fa6b854cc963b6562abe1861cbdb85c222
  HelloWorld: 0x0a926a36ec5bf177c7724d0d1a85aa15e965916c
Saving successful migration to network...
  ... 0x548eab4802922e75dedfbb63ce158c4863bddcc5e6fc14f0396f109be13d8794
Saving artifacts...
Running migration: 2_deploy_contracts.js
Saving successful migration to network...
  ... 0x308b6e327d3cbc901cd49d380f56d30eb422efc3232d54115a2ef025dfc68f0c
Saving artifacts...

Actually, Truffle has a minor issue running on Windows 10 where the truffle.js has name conflicts with the main truffle command. You'll want to rename truffle.js to truffle-config.js

Clear out all previous builds/migrations. Delete the build directory and run truffle migrate --reset.

If the above two methods don't work, restart testrpc to clear out any previous migrations on your local blockchain. Then run truffle migrate

answered Apr 27, 2018 by Perry
• 17,100 points

edited Aug 10, 2018 by Omkar

This solved the problem. Thanks. If I am not wrong, Windows Operating Systems considers truffle-config.js file and not truffle.js file right?

Yes @Karan, you are right.

Related Questions In Blockchain

+1 vote
1 answer

How can I initiate a transaction on ethereum private network using mobile device?

There is no android wallet to connect ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,400 points
914 views
0 votes
1 answer

How can i create a simple P2P network on a blockchain?

To develop your own cryptocurrency, you need ...READ MORE

answered Apr 20, 2018 in Blockchain by Christine
• 15,790 points
2,043 views
0 votes
2 answers

How do I interact with a smart contract on a private network through web3.js

I found a blog that explains how ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,370 points
3,967 views
+1 vote
2 answers

Hyperledger - Can I have some instances on one network while on a Virtual Box?

Yes, you can connect multiple instances to ...READ MORE

answered Aug 1, 2018 in Blockchain by Omkar
• 69,220 points
909 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,939 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,479 views
0 votes
2 answers

Why is network already up to date while trying to deploy a contract on truffle?

I guess you have ganache running already ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,400 points
4,591 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP