10

I have been running into the specified in the title.

I have developed a smart contract and have successfully compiled and deployed it to the network as follows: 1. Run testrpc 2. truffle compile 3. truffle migrate

However, the error above is still being shown. I then tried deleting the build file and followed the steps below: 1. Run testrpc 2. truffle compile 3. truffle migrate --network rinkeby

The error was still being shown.

Below is the truffle.js file

module.exports = {
  migrations_directory: "./migrations",
  networks: {
development: {
  host: "localhost",
  port: 8545,
  network_id: "*" // Match any network id
},
rinkeby: {
  host: "localhost", // Connect to geth on the specified
  port: 8545, 
  network_id: "*",
}

} };

If anybody has faced any similar issues and have resolved it, I would greatly appreciate it if you could share how you have resolved it.

Thanks in advance

Sho0310
  • 101
  • 1
  • 1
  • 5
  • Can you add your full `geth` start command? – Adam Kipnis Feb 08 '18 at 23:05
  • Update: I have just noticed the contract is not getting deployed correctly with testrpc, and I have tried to migrate the contract by running a geth node through: `geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --unlock
    ` and I am getting the error below. Running migration: 1_initial_migration.js Deploying Migrations... ... undefined Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: authentication needed: password or unlock @AdamKipnis any idea?
    – Sho0310 Feb 12 '18 at 21:08
  • You need to use the —password option with geth to unlock the account. – Adam Kipnis Feb 12 '18 at 23:37
  • When `personal.unlockAccount("Address", "Password")` is run on geth console, it returns true though. And the error still persists – Sho0310 Feb 13 '18 at 01:05
  • UPDATE: I am now getting the error: `Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: insufficient funds for gas * price + value` – Sho0310 Feb 13 '18 at 10:41
  • This isn't really an appropriate question for the site. You might be ill-treated here. I recommend that you post your question to a site with the word "forum" in the name. – SaganRitual Mar 10 '18 at 03:51

8 Answers8

14

For me, the following steps worked: create the file 2_deploy_contract.js in the migration folder with the code

var myContract = artifacts.require("myContract");

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

And run on terminal

$ truffle migrate --reset

I didn't need to change any settings in the truffle-config.js

7

I had the same issue and created the file 2_deploy_contract.js in the migration folder with the code:

var myContract = artifacts.require("myContract");

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

I also checked the truffle-config.js at the root of the folder with the default settings:

rinkeby: {
  host: "localhost", 
  port: 8545, 
  from: "0x0085f8e72391Ce4BB5ce47541C846d059399fA6c", // default address to use for any transaction Truffle makes during migrations
  network_id: 4,
  gas: 4612388 // Gas limit used for deploys
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Hel
  • 137
  • 2
  • 9
4

Tl;dr:

  1. Add a new migration to your migration folder and name it as following: 2_deploy_contract.js

PS: you can name it whatever. 2_deploy_yourmomsdonuts.js would work too. Just pay attention to the number - it has to correspond with the order. 2. Add this code snipper to this file:

Replace HelloWorld with the name of your contract that didn't get deployed (see in your console what contract has thrown an error)

var HelloWorld = artifacts.require('HelloWorld');

module.exports = function (deployer) {
  deployer.deploy(HelloWorld);
};
  1. Run truffle migrate --reset or truffle deploy --reset - These are aliases and do the same thing. You can also run both of them to be on the safe side.

  2. You should see that your contract got deployed to your network.

  3. Finally truffle console and invoke your function again. Voila.

Why did you have to manually add a migration? The problem was that your smart contract didn't get deployed/did't get recognized so by manually adding your migration, you are telling Truffle which file should get deployed.

Dharman
  • 30,962
  • 25
  • 85
  • 135
yavnelf
  • 169
  • 1
  • 2
  • 12
0

There are a lot of different error messages through the original post and the comments. I think the best thing is to provide a step-by-step guide to deploying to Rinkeby using Truffle:

Geth

To start, create the account you want to use for this test. It looks like you've already done this, but including this for completeness. Note, that I am using a custom keystore directory because I like to keep my keystores separate across different networks.

geth --rinkeby --keystore ./eth/accounts/rinkeby/keystore account new

After entering your password, you will get back your new address. Once the account is created, create a new text file called pass.txt and put the password you used to create the account inside the file and save it.

Obviously this is not the preferred way of keeping passwords safe. Do not do this in a live environment

You'll also need to add some ether to your account. Use faucet.rinkeby.io.

Next, make sure you are properly starting starting Geth and it's in the correct state. I use custom data and keystore directories. You can use the default if you choose.

geth --rpc --datadir ./eth/geth/data/rinkeby --keystore ./eth/accounts/rinkeby/keystore --rinkeby --rpccorsdomain '*' --rpcapi 'web3,eth,net,personal' --unlock '0x25e6C81C823D4e15084F8e93F4d9B7F365C0857d' --password ./pass.txt --syncmode="full" --cache=1024

Replace my address with the one you created. When started, you should see something like this:

INFO [02-13|17:47:24] Starting peer-to-peer node               instance=Geth/TrustDevTestNode/v1.7.3-stable-4bb3c89d/windows-amd64/go1.9
INFO [02-13|17:47:24] Allocated cache and file handles         database=C:\\cygwin\\home\\adamk\\eth\\geth\\data\\rinkeby\\geth\\chaindata cache=1024 handles=1024
INFO [02-13|17:47:47] Initialised chain configuration          config="{ChainID: 4 Homestead: 1 DAO: <nil> DAOSupport: true EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 1035301 Engine: clique}"
INFO [02-13|17:47:47] Initialising Ethereum protocol           versions="[63 62]" network=4
INFO [02-13|17:47:47] Loaded most recent local header          number=1766839 hash=6d71ad…ca5a95 td=3285475
INFO [02-13|17:47:47] Loaded most recent local full block      number=1766839 hash=6d71ad…ca5a95 td=3285475
INFO [02-13|17:47:47] Loaded most recent local fast block      number=1766839 hash=6d71ad…ca5a95 td=3285475
INFO [02-13|17:47:47] Loaded local transaction journal         transactions=0 dropped=0
INFO [02-13|17:47:47] Regenerated local transaction journal    transactions=0 accounts=0
INFO [02-13|17:47:48] Starting P2P networking
2018/02/13 17:47:50 ssdp: got unexpected search target result "upnp:rootdevice"
2018/02/13 17:47:50 ssdp: got unexpected search target result "uuid:2f402f80-da50-11e1-9b23-001788409545"
2018/02/13 17:47:50 ssdp: got unexpected search target result "urn:schemas-upnp-org:device:basic:1"
2018/02/13 17:47:50 ssdp: got unexpected search target result "upnp:rootdevice"
2018/02/13 17:47:50 ssdp: got unexpected search target result "uuid:2f402f80-da50-11e1-9b23-001788409545"
INFO [02-13|17:47:51] UDP listener up                          self=enode://751bc7825c66f9ab5b87f933d6b6302fd14434b7ed4d7c921c3f39684915843078eda4e995c927561067946b4f856ca2a35ea7285c27439c0f535338aaca80e9@172.88.30.226:30303
INFO [02-13|17:47:51] RLPx listener up                         self=enode://751bc7825c66f9ab5b87f933d6b6302fd14434b7ed4d7c921c3f39684915843078eda4e995c927561067946b4f856ca2a35ea7285c27439c0f535338aaca80e9@172.88.30.226:30303
INFO [02-13|17:47:51] IPC endpoint opened: \\.\pipe\geth.ipc
INFO [02-13|17:47:51] HTTP endpoint opened: http://127.0.0.1:8545
INFO [02-13|17:47:52] Unlocked account                         address=0x25e6C81C823D4e15084F8e93F4d9B7F365C0857d
  • Confirm that network=4.
  • Confirm that the last line showing the account being unlocked succeeds without error.
  • Once your node starts, make sure it is fully synced.

Truffle

truffle.js (or truffle-config.js if Windows):

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    rinkeby: {
      host: "localhost",
      port: 8545,
      from: "0x25e6c81c823d4e15084f8e93f4d9b7f365c0857d",
      network_id: "4"
    }
  }
};

Use Truffle console to confirm your node and account:

$ truffle console --network rinkeby
truffle(rinkeby)> web3.eth.blockNumber
1767136 // Confirm latest block number on https://rinkeby.etherscan.io/
truffle(rinkeby)> web3.eth.getBalance('0x25e6c81c823d4e15084f8e93f4d9b7f365c0857d');
{ [String: '2956062100000000000'] s: 1, e: 18, c: [ 29560, 62100000000000 ] }

Exit the console and run your compile/migrations (this will take about a minute to run):

$ truffle migrate --network rinkeby
Compiling .\contracts\LoopExample.sol...
Writing artifacts to .\build\contracts

Using network 'rinkeby'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0xf377be391a2eaff821c0405256c6a1f50389650ea9754bdc2711296b02533e02
  Migrations: 0x9cef8d8959d0611046d5144ec0439473ad842c7c
Saving successful migration to network...
  ... 0x4cf989973ea56a9aa4477effaccd9b59bfb80cc0e0e1b7878ff25fa5cae328db
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying LoopExample...
  ... 0x4977c60fd86e1c4ab09d8f970be7b7827ee25245575bfbe206c19c6b065e9031
  LoopExample: 0x56b9c563f287cdd6a9a41e4678ceeeb6fc56e104
Saving successful migration to network...
  ... 0x5628d64dc43708ccb30d7754a440e8e420a82a7b3770539cb94302fe7ad9098f
Saving artifacts...

Confirm the deployment on etherscan: https://rinkeby.etherscan.io/address/0x56b9c563f287cdd6a9a41e4678ceeeb6fc56e104

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
0

I came across the same problem and the following solved it for me:

...configuring the 1_initial_migration.js to deploy the TodoList contract for this to work. When doing the truffle init it deploys a Migration.sol contract, so you have to change that:

var TodoList = artifacts.require('../contracts/TodoList.sol');
module.exports = function(deployer) {
  deployer.deploy(TodoList);

}

source: https://medium.com/@addibro/i-had-to-fiddle-around-with-truffle-compile-and-migrate-first-and-also-configuring-the-9bc7a6ea8e3e

Diogo Melo
  • 1,735
  • 3
  • 20
  • 29
  • Can you share how you would deploy a contract with a constructor and its arguments? E.g., `constructor(address1 _add1, address2 _add2, uint value)` – Ndrslmpk Nov 15 '21 at 14:11
0

I found the solution for this problem. i change my migration file name from AdvancedStorage_migrate.js to 2_AdvancedStorage_migrate.js

truffle can't able find a migration file if you didn't save your migration file without number so, you must be save your migration file like this(2_AdvancedStorage_migrate.js )

this problem is not rise from truffle configuration so don't touch truffle configuration.js file

Abdul Haq
  • 9
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '22 at 12:18
0

Solution :

In My case I am using truffle-contract to load contract abi . By default truflle-contract network id is 1.

But I am using goreli network id 5. We need to setNetwork while loading contract `

            const contract = require('truffle-contract');   
            const MyContract = contract(MyContract);    
    
            MyContract.setProvider(web3.currentProvider);    
            MyContract.setNetwork(5) 

`

Vyas Reddy
  • 1,226
  • 1
  • 13
  • 24
-3

 const conract = artifacts.require('conractArtifact');

//update this
module.exports = function (deployer) {}
//to this
module.exports = async (deployer) => {}
//or to this
module.exports = fucntion (deployer) {}
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '22 at 00:09