Testing Deployed Smart Contract on Truffle - ethereum

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

Related

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,
},
};

Unable to deploy an ERC 720 token in Mumbai Test says insufficient funds

I was trying to deploy an ERC 721 token using truffle in Polygon's mumbai testnet.
And i have 2.8296 Matic in my metasmask wallet which i got from their faucet. But when i try to run
truffle migrate --network matic
it says
Error: *** Deployment Failed ***
"Migrations" could not deploy due to insufficient funds
* Account: 0x12aADAdd301d22c941DACF2cfa7A9e2019972F61
* Balance: 0 wei
* Message: insufficient funds for gas * price + value
* Try:
+ Using an adequately funded account
+ If you are using a local Geth node, verify that your node is synced.
Am i doing something wrong? What sould be the gas and gas price i should mention in truffle config file.
Here is my truffle-config file
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
matic: {
provider: () => new HDWalletProvider(process.env.MNEMONIC, `https://rpc-mumbai.maticvigil.com/v1/91fdbb5c2f37c699621ss7d2b8b127fc1a123060
`),
network_id: 80001,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
enter image description here
I am pretty sure there is no balance of this account 0x12aADAdd301d22c941DACF2cfa7A9e2019972F61 in Mumbai-Testnet

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"
}
}
}```

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

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'

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: "*"
}
}
};