How to fix "Unknown network "ganache". See your Truffle configuration file for available networks." - ethereum

I'm trying to deploy a contract to rinkeby. I'm using the following command:
$ truffle migrate --networks rinkeby
Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/Voting.sol
> Artifacts written to ./public/contracts/build/
> Compiled successfully using:
- solc: 0.5.8+commit.23d335f2.Emscripten.clang
Unknown network "ganache". See your Truffle configuration file for available networks.
Truffle v5.0.22 (core: 5.0.22)
Node v11.6.0
It works witch ganache-cli but it doesn't work with rinkeby, because its giving me the error of Unknown network "ganache". See your Truffle configuration file for available networks as showed in the result above.
This is my truffle-config.js:
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
contracts_build_directory: path.join(__dirname, "./public/contracts/build/"),
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: 1000,
gas: 4612388,
gasPrice: 25000000000,
total_accounts: 20,
mnemonic
},
rinkeby: {
provider: () => new HDWalletProvider(mnemonic, infuraURL),
network_id: 4,
gas: 4612388,
gasPrice: 25000000000,
},
},
solc: {
optimizer: {
enabled: true,
runs: 200
}
}
};

For anyone having this error, my problem was that I was writting wrong the command. The correct form should be:
truffle migrate --network rinkeby # Network is without the 's'

Related

Hardhat verify command not present

I've installed estherscan from npm, but the verify command is still not present. When I try to verify a contract I get the error that the verify task does not exist.
This is my hardhat.config.js file,
`/**
* #type import('hardhat/config').HardhatUserConfig
*/
require('dotenv').config();
require("#nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY, ETHERSCAN } = process.env;
module.exports = {
solidity: "0.8.9",
defaultNetwork: "polygon_mumbai",
networks: {
hardhat: {},
polygon_mumbai: {
url: API_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
},
etherscan: {
apiKey: ETHERSCAN
}
}`
When I try to verify I get the error "Error HH303: Unrecognized task verify"
When I run the command npx hardhat I don't see any verify task on the menu
I've tried installing the etherscan verify plugin for hardhat using npm install --save-dev #nomiclabs/hardhat-etherscan
I forgot to import the plugin into hardhat.config.js,
solution is to import it before running the command.
require("#nomiclabs/hardhat-etherscan");

truffle doesnt migrate to new chain

I was following some tutorial and everything worked fine. I decided to make a new project to test myself out. After writing the contracts and making a new ganache workspace, when I run truffle migrate, it just says:
Compiled successfully using:
- solc: 0.8.7+commit.e28d00a7.Emscripten.clang
It doesnt say anything regarding the migrations.
When I run truffle networks, it says: Contracts have not been deployed to any network.
Also, when I run truffle develop, when it lists down the accounts, its showing the old accounts from my older ganache workspace.
truffle-config.js:
module.exports = {
networks: {
ganache: {
host: "127.0.0.1",
port: 7545,
network_id: "*"
},
},
compilers: {
solc: {
version: "^0.8",
optimizer: {
enabled: true,
runs: 200
},
},
},
contracts_directory: './src/contracts/',
contracts_build_directory: './src/abis/',
mocha: {
useColors: true,
},
};

Why does truffe migration command doesn't work ? for me

Could not connect to your Ethereum client with the following parameters: - host > 127.0.0.1 - port > 7545 - network_id > * Please check that your Ethereum client: - is running - is accepting RPC connections (i.e., "--rpc" option is used in geth) - is accessible over the network - is properly configured in your Truffle configuration file (truffle-config.js)
Truffle v5.3.9 (core: 5.3.9) Node v16.3.0
This is from this video https://youtu.be/XLahq4qyors?t=1385
AND yes my ganache is opened , my truffle-config.json is configured properly with correct port and all tried other solutions from this work but unfortunately it did not work
My config
require('babel-polyfill');
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
},
},
contracts_directory: './src/contracts/',
contracts_build_directory: './src/abis/',
compilers: {
solc: {
optimizer: {
enabled: true,
runs: 200
},
evmVersion: "petersburg"
}
}
}```

Testing Deployed Smart Contract on Truffle

I'm having trouble testing a contract using truffle. I have the latest version of truffle installed as well a TestRPC.
It's to my understanding that the latest version of truffle comes with a client for testing SmartContracts so TestRPC isn't needed any more.
I have a simple contract my Migrations looks like so:
var Migrations = artifacts.require("./Migrations.sol");
var OrdersFacilitator = artifacts.require("./OrdersFacilitator.sol")
module.exports = function(deployer) {
deployer.deploy(Migrations);
deployer.deploy(OrdersFacilitator);
};
When I run truffle develop I see that 10 test accounts are created.
Accounts:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
(1) 0xf17f52151ebef6c7334fad080c5704d77216b732
//...
My Truffle js is configured like so:
networks: {
development: {
host: "localhost",
port: 9545,
network_id: "*"
}
}
When I run the name of my contracts I can see its deployed with the information:
//...
class_defaults:
{ from: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
gas: 6721975,
gasPrice: 100000000000 },
currentProvider:
HttpProvider {
host: 'http://127.0.0.1:9545/',
timeout: 0,
user: undefined,
password: undefined,
headers: undefined,
send: [Function],
sendAsync: [Function],
_alreadyWrapped: true },
network_id: '4447' }
the Network Id and the port seem to match the configuration fine, and I can see the information when I type the contract name, However when I try to gain access to it though
var facilitator;
OrdersFacilitator.deployed().then(x => facilitator = x);
I Get an Error:
OrdersFacilitator has not been deployed to detected network (network/artifact mismatch)
I've tried deleting the build folder and migrating all with the --reset flag but that doesn't seem to work. How can I Tested my deployed contract
I've seen similar issues withe Truffle projects attempting the same thing. The solution may be to reset the project to a non-cached state.
You can try running truffle compile (and/or truffle migrate) with the --reset flag. This will remove the build dir and recompile everything.
To fix the issue I've explicitly set the network options and network id.
//Start Test RPC with an Explicit Network
testrpc --network-id 1337
Then I've created an explicit network for TestRPC:
networks: {
testrpc:{
host: "localhost",
port: 8545,
network_id: "1337"
}
}
Now when I Migrate Explicitly to my new network:
truffle migrate --network testrpc --reset
truffle console --network testrpc
This seems to map properly to the correct network

Truffle migrate Error (after run testrpc)

I can´t migrate the standart contracts that come with truffle compile. Here´s what i do:
truffle init
truffle compile
open other terminal and run testrpc
truffle migrate
and the first three step is smooth operation,but when i run truffle migrate ,it appears
Error: No network specified. Cannot determine current network.
at Object.detect (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43157:23)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:200497:19
at finished (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43085:9)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:198408:14
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:68162:7
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:163793:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160353:16
at replenish (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160873:25)
at iterateeCallback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160863:17)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160838:16
My version list:
node 9.1.0
truffle 4.0.1
testrpc 6.0.3
Thank you!
You should specify the network in the configuration file truffle.js, which is located in the root of your project folder.
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
}
};
Truffle configuration#networks
Simple Solution:
Problem: this configuration is coming today while you run commend
"truffle init" in terminal. there is no configration defined to communicate with ethereum cli (like geth or testrpc )
// module.exports = {
// // See <http://truffleframework.com/docs/advanced/configuration>
// // to customize your Truffle configuration!
// };
So, you have to change it like below in truffle.js
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545, // your rpc port (like geth rpc port or testrpc port )
network_id: "*"
}
}
};