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,080 points
490 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,020 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,350 points
56 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
148 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,170 points
369 views
+1 vote
2 answers
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
158 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
• 67,600 points
90 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer