How can I disconnect Metamask wallet using web3.js - ethereum

I want to disconnect metamask wallet using web3 or ether.js
But I cannot find any function to disconnect programly.

It can not be done programmatically, because it is up to the user to disconnect/connect, you have no control(from code level) over metamask wallet. You just simulate flow of logging in and logging out by checking if you can get access to user's wallet accounts.

Related

How to deploy hardhat contract to mainnet without ALCHEMY or INFURA?

How to deploy hardhat contract to mainnet without ALCHEMY or INFURA ?
Alchemy, Infura, and others, are services offering connection to nodes of the Ethereum network.
Contract deployment means that you broadcast a transaction with specific parameters (data field containing the compiled bytecode, to field empty). But you can only broadcast a transaction to the rest of the network from a node connected to the network.
So apart from using a third-party service, you can also run your own node. For example using the go-ethereum client software.
Then you'll be able to broadcast the transaction through this your own node, instead of a third-party one.

How to prefund a hardhat local node address

On spinning up a hardhat node locally, I get 10 addresses pre funded with 10k ETH. But none of these show up on metamask when I connect it to localhost:8545. As a result I'm not able to interact with a dapp deployed locally
Am I doing something wrong?
Usually, the back-end development project provides funded accounts which you can enter into Metamask, It's not like the Goerli or (now defunct) Rinkeby test networks where you can visit a site and have some ETH added to your test account because those test networks are hosted. You need to spin up a local project and have it provide funded accounts.
Such an example is Lesson 9: Hardhat Smart Contract Lottery in (Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript by Free Code Camp)
here is the code ...
https://github.com/PatrickAlphaC/hardhat-smartcontract-lottery-fcc
If you run that project it generates a number of addresses which you can connect to in Metamask.
MetaMask has no way of knowing which of your local accounts you want to import, or which are funded (prior to the import).
So you need to import the accounts to MetaMask manually using the private keys provided by Hardhat.

Ethereum wallet shows it has ethers but geth does not show the balance

I am starting to learn ethereum. I have downloaded the Ethereum Wallet, created two accounts and using Rinkeby faucet I got 3 ethers in one of the account. I can see the balance in my wallet. I then ran geth --testnet --datadir d:\data and it started syncing. I let it run for a day and now it slowly adds new blocks. I started another get console and attached it to get.ipc. On the console, I did:
eth.accounts
I see both the accounts in my wallet with first account set as coinbase. But when I ran
eth.getBalance(accounts[0])
I get 0 balance. What might be something I might have overlooked? Thanks in advance
connect to Rinkeby faucet using metamask chrome extension. Provide your account details there you can check that you received ether or not.
It will show you the balance once it has completed syncing. For me it took more than one day to sync, then I could see the account balance properly.
Try eth.syncing to check the status and if eth.blockNumber gives 0 as output that means syncing hasn't finished yet.

How to get confirm password when I use Ethereum Wallet by ganache development?

I'm writing smart contracts in Ethereum, using ganache and truffle. Contracts was deployed to the chains and I use Ethereum Wallet to get all the accounts created by ganache, but when I want to test the contracts or send eth I get this information:
And I got the private key but Ethereum Wallet import account is disabled:
How do I use these accounts to test my contracts by Ethereum Wallet?

Remix Ethereum where goes the contract?

I don't understand where actually the smart contract goes, when I click on create under remix.ethereum.org. If I choose for example the Injected Web3, this should publish the contract to the ropsten test net, right? But how can I access the contract then? When I use metamask it injects me the right provider when I use web3.js, but how can I find this contract now, if I don't want to use the injected web3, but manually choose the provider address in web3.js? Can I access the smart contract this way?
Edit: I don't know what should be wrong about my question.I seriously find nothing about how how to connect to a smart contract for example in the ropsten test network without injected web3. Normally you do this in web3.js:
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
}
But if you don't have an injected web3, then you use the localhost. But I cannot connect then to the smart contract, because it does not know, in which net I actually published the smart contract, right?
Remix has 3 different environment options that can be used to deploy/test Solidity contracts: JavaScript VM, Injected Web3, and Web3 Provider. This option can be changed under the Environment drop down under the Run tab. (It looks like you've got this part...just documenting for completeness).
JavaScript VM: This is Remix's own internal sandbox. It does not connect to MainNet, TestNet, or any private network. It's an in-memory blockchain that can be used for simple testing and quick mining.
Injected Web3: This is the option to use for the browser plugin (MetaMask). Here, you are telling Remix to defer all control of the blockchain integration to the MetaMask plugin. At this point, MetaMask controls which network you are connecting to. In the plugin, you can connect to MainNet, Ropsten, Rinkeby, etc through Infura's node network. In this case, you're not running a node locally. MetaMask also has a localhost option where you can run your own node locally and MetaMask will send all transactions to it (this local network can be a private network using any node client or you can use a test blockchain like TestRPC).
Web3 Provider: This allows you to enter a URL in Remix to connect to the blockchain. The most common setup here is to be running a local node and connecting to it through it's IP/port. This is pretty much the same as using MetaMask's localhost option, but you're just cutting the plugin out of being the middleman. Just like option #2, the network your connected to depends on how you've configured your local node (it can be main, test, private, etc.).
So, "where your smart contract goes" depends on which of the configurations you have set up. Selecting Injected Web3 does not automatically mean your contract is being deployed to Ropsten. It depends on which network you have selected in the MetaMask plugin.
When using MetaMask through Remix, you need to use the plugin to select the appropriate account and confirm/reject transactions. Selecting the account is a bit confusing because Remix doesn't pick up all of the accounts imported into MetaMask. The Account dropdown will only have the account currently selected in MetaMask. In addition, if you change the account in MetaMask, you have to reload Remix for it to have that account selected in the dropdown. It does NOT automatically detect when the account has changed in MetaMask.
Once the account is properly selected (and assuming you're using an account that holds ether), you can now deploy your contract. Hit Create in Remix and then switch over to the plugin again. There, you should see a pending transaction waiting to approved. Select the transaction, then click Submit.
Transaction list:
Approve/Reject screen:
After submitting, it'll take a few seconds for the transaction to be mined. MetaMask will show when it's completed. That's it! To interact with the contract, you can initiate your transactions through Remix similar to the deployment steps above.