Could not connect to Ethereum client (testrpc) - ethereum

I've properly installed geth, truffle and testrpc. Now I'm trying to do some Ethereum contract tutorials. I initialized project by truffle init, so the project folder with default contracts was created, then I ran testrpc and compiled contracts by typing truffle compile (build directory was created successfully). The thing is, truffle test is not working as if there is no testrpc running.I'm using Git Bash on Windows. What might be the problem?
Screen

check this out
You need a test file in your directory before you can run truffle test
You need two CMD window,
one to run testrpc command (Do not terminate),
second window to compile
To compile, run the command below
Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")
solc = require('solc')
sourceCode = fs.readFileSync('ContractFile.sol').toString()
compileCode = solc.compile(sourceCode)
//Get the interface of contract
contractABI = JSON.parse(compileCode.contracts[':ContractFile'].interface)
//Get the bytecode of the contract
bytecode = compiledCode.contracts[':ContractFile'].bytecode
//Ready to deploy
ContractFileContract = web3.eth.contract(contractABI)
//use the object above to deploy the contract
ContractDeployed = ContractFileContract.new({data: bytecode, from: web3.eth.account[0], gas: 4700000})
//Check your testrpc console.
Don't forget to declear solidity version at the top of you contract.

Related

"npx hardhat accounts" not available in Hardhat latest version 2.9.9

I have installed the latest version of hardhat. It installed fine.
After setting hardhat up and installing all the required packages, when I run:
npx hardhat accounts
It gives an error:
Error HH303: Unrecognized task accounts
It seems like 'account' task has been removed in the latest version of hardhat. My question is now to get the list of wallet accounts that hardhat generates?
I have the same situation on 2022-08-16.
To get the available accounts, I use the npx hardhat node command.
The command sequence I performed was:
$ npx hardhat --version
2.10.1
$ npx hardhat accounts
Error HH303: Unrecognized task accounts
For more info go to https://hardhat.org/HH303 or run Hardhat with --show-stack-traces
$ npx hardhat node
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
Accounts
========
WARNING: These accounts, and their private keys, are publicly known.
Any funds sent to them on Mainnet or any other live network WILL BE LOST.
Account #0: 0xf39Fd6e51a...ffFb92266 (10000 ETH)
Private Key: 0xac0974bec39a1...478cbed5efcae784d7bf4f2ff80
Account #1: 0x70997970C51812...b50e0d17dc79C8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a...9dc9e86dae88c7a8412f4603b6b78690d
.
.
.
This is because the accounts tasks is not included in the latest release. Add the following in your hardhat.config.js
task("accounts", "Prints the list of accounts", async () => {
const accounts = await ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
im not sure but I managed to fix this by migrating waffle to Beth chai masters as required and rm from config the waffle and add the chai masters
after that could not get accounts els how than "npx hardhat node" looks like accounts are displayed when launching the node if it can help!
I use yarn hardhat node to display a list of hardhat accounts on the terminal

Token doesn't want to deploy to a blockchain

I have created and compiled a smart contract and created my deploy token file as well. When I run ganache-cli on one terminal it gives me '''eth_getTransactionByHash''' and while the brownie run scripts is running on the other terminal it says '''awaiting transaction from mempool'''
I logged into my MetaMask account as well and created a new Account with the RPC and chain ID provided.
Please help.
I had the same issue when running ganache-cli. I fixed it by passing some parameters
ganache-cli --port 8545 --gasLimit 12000000 --accounts 10 --hardfork istanbul --mnemonic brownie

accounts[0] returns network name in string

I am running a set of smart contracts in test mode in order to perform some initial tests. However and very strangely, when running truffle migrate --network testrpc and using accounts[0] in my migration files, I get the following error:
Error: Provided address "t" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted.
In this string, "t" is in fact the first letter of testrpc. If I use accounts[1] I get a "e", etc...
I was previously using testrpc command line encironment and later switched to ganache-cli to try and solve the issue. Unfortunately nothing worked quite as I expected and I am still stuck with the issue.
I am running on Ubuntu so that may cause the issue?
EDIT 1: Migration file:
// Starting deployment of asset
module.exports = async function(deployer, network, accounts) {
// owner wallet
var wallet = accounts[0];
};
I didn't find why it didn't work with testrpc, so I switched to ganache-cli which also provided the same issue... I finally resigned myself to use Ganache Client app, and it worked...

web3 json rpc error "" when attempting transactions

We're using web3 to connect to the rinkeby test ethereum network. When doing so through geth, via localhost, with the below web3 command:
var web3 = new Web3('http://localhost:8545');
We don't get any errors. We use this command to start geth:
geth --rinkeby --rpc --rpcapi="personal,eth,network,web3,net" --ipcpath "~/Library/Ethereum/geth.ipc"
However when we try using the rinkeby test network directly:
var web3 = new Web3('https://rinkeby.infura.io/');
We get this error:
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (errors.js:42)
at XMLHttpRequest.request.onreadystatechange (index.js:73)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
at XMLHttpRequest.js:493
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:353)
at MessageQueue.js:118
at MessageQueue.__guardSafe (MessageQueue.js:316)
Most of the operations work on both networks, but .send() calls fail when connecting to the rinkeby network directly.
We think it's an issue with authentication, since other commands succeed that don't perform transactions. However, we tried using the HDWalletProvider and none of our accounts created via geth have mnemonics.
Any advice or troubleshooting steps would be appreciated. Thanks
Transactions have to be signed. When you send a transaction via your local geth node, it knows the private key corresponding to the address you're sending from, so it can sign the transaction for you (once you unlock the account).
A public node like Infura (fortunately!) doesn't know your private key, so it can't sign transactions for you. You'll need to sign them locally and then send them using sendSignedTransaction.

Ethereum deployed contract not defined in Geth Javascript console

I cannot access a deployed and mined Ethereum contract on a private network from the Geth Javascript console. Not sure where the issue is, any help is appreciated.
Thank you in advance for your time.
Scenario
I launched my Geth as below
geth --datadir ~/.ethereum/myProject --networkid 1234 --rpc --rpcport 8546 --rpcapi "eth,net,web3" --unlock 0 console
I've deployed and mined an Ethereum contract (to simplify things, I've used the default MetaCoin contract provided by Truffle), and I got the trx and contract address back.
I can access it from the Truffle console but if I try from the Geth Javascript console I get an error.
Please refer to the pictures below:
Truffle console
Geth javascript console
Software used
Geth (v1.7.3-stable)
NodeJS (v6.12.3)
TestRPC (v6.0.3 (ganache-core:2.0.2))
Truffle (v4.0.5)
Geth does not know about MetaCoin. In Geth console, you need to do:
var MetaCoin = web3.eth.Contract(metaCoinJsonAbi, itsAddress);
// or web3.eth.contract depending on the version of Web3
Then you can use it. Refer to this.