Skip to main content
193 votes
Accepted

How are ethereum addresses generated?

Recently this article came to my attention that is way more in depth and technical than my more accessible version below. It also walks you through how to generate one on your own. I highly recommend ...
tayvano's user avatar
  • 16k
70 votes
Accepted

Get public key of any ethereum account

You can if and only if a transaction has been sent from the account. When you send a tx, you sign the transaction and it includes these v r and s values. You parse these from the signed tx and then ...
tayvano's user avatar
  • 16k
66 votes
Accepted

What is nonce in Ethereum? How does it prevent double spending?

What is nonce in Ethereum? If you refer to the Glossary at Github Wiki, there are two types of nonce used in Ethereum. Account nonce - It's simply the transaction count of an account Account nonce: ...
Achala Dissanayake's user avatar
56 votes
Accepted

How does a contract find out if another address is a contract?

This works: function isContract(address _addr) private returns (bool isContract){ uint32 size; assembly { size := extcodesize(_addr) } return (size > 0); } The assembly language that ...
Thorkil Værge's user avatar
55 votes

What is an 'EOA' account?

This is an Externally Owned Account, so your normal Ethereum address, not a wallet contract. In general, there are two types of accounts: externally owned accounts, controlled by private keys, and ...
Roland Kofler's user avatar
36 votes
Accepted

How can I detect change in account in Metamask?

As suggested by Metamask FAQs this might be an option: var account = web3.eth.accounts[0]; var accountInterval = setInterval(function() { if (web3.eth.accounts[0] !== account) { account = web3....
qbsp's user avatar
  • 4,367
34 votes

What is coinbase?

Crypto currencies and blockchains in general allow you to work with arbitrarily many accounts at the same time. However often people want to have a default/primary account (e.g. miners have a ...
Péter Szilágyi's user avatar
34 votes
Accepted

In the truffle console, how to set and get current account?

In truffle console: var accounts; // in web front-end, use an onload listener and similar to this manual flow ... web3.eth.getAccounts(function(err,res) { accounts = res; }); var account1 = ...
Rob Hitchens's user avatar
  • 55.4k
34 votes

How can I detect change in account in Metamask?

From the MetaMask docs: window.ethereum.on('accountsChanged', function (accounts) { // Time to reload your interface with accounts[0]! }) window.ethereum.on('networkChanged', function (networkId) { ...
rstormsf's user avatar
  • 4,357
34 votes
Accepted

Difference between Ganache and Truffle

Ganache allows you to create a private Ethereum blockchain for you to run tests, execute commands, and inspect state while controlling how the chain operates. It gives you the ability to perform all ...
Shane Fontaine's user avatar
27 votes
Accepted

Can I use the same private key for Ethereum and Bitcoin?

Yes, both cryptocoins use the same elliptic curve SECP256K1. Perhaps a better alternative is to use a BIP32 wallet. You have a master key that is not directly used for transactions, but it is used to ...
Ismael's user avatar
  • 30.5k
24 votes

How does a contract find out if another address is a contract?

Full credit to @AnAllergyToAnalogy for the caution item. I made an example to demonstrate that a constructor will trick this method. Posting for others who might come across this thread. In practice, ...
Rob Hitchens's user avatar
  • 55.4k
23 votes

How can I detect change in account in Metamask?

Using web3 version 1.0.0, the metamask provider exposes an 'update' event you can listen to on it's publicConfigStore. web3.currentProvider.publicConfigStore.on('update', callback); Your callback ...
Brian Ethier's user avatar
21 votes
Accepted

Concurrency patterns for account nonce

I haven't yet got to the point where I can test any of these things, but my gut feel is that the Singleton Nonce Manager would be the way to go, with a few enhancements: Make it a singleton ...
Sentinel's user avatar
  • 1,238
19 votes

How does a contract find out if another address is a contract?

Since this is security related, it's helpful to emphasize https://stackoverflow.com/questions/37644395/how-to-find-out-if-an-ethereum-address-is-a-contract: The top-voted answer with the isContract ...
eth's user avatar
  • 86k
18 votes
Accepted

How to unlock accounts programmatically after the node has started?

Just to clarify: You would like to run a geth node starting up with the accounts all locked as per the default You later want to run a 'geth attach' command to unlock one or more accounts for a ...
BokkyPooBah's user avatar
  • 40.3k
18 votes

How do I backup my ether accounts?

PLEASE MAKE SURE TO ALSO BACKUP YOUR PASSWORDS Each key file (as described in @Ethan's answer) is encrypted and only usable with the correct password. Another safety tip: Before deleting any key ...
eth's user avatar
  • 86k
18 votes

Account uniqueness guaranteed?

Ethereum addresses are 160 bit hashes, meaning there are 2^160 possible hashes. Per the birthday problem, the chance of a collision rises to 50% when there are about 2^80 accounts created. To give ...
Nick Johnson's user avatar
  • 8,174
18 votes
Accepted

Error "no key for given address or file" when unlocking coinbase account

We were getting the same error and it turned out that there were two conflicting keyfiles. One in the default (~/.ethereum) and one in a custom location that we had specified using --datadir. In the ...
Peter Munnings's user avatar
18 votes
Accepted

isContract function using EVM assembly to get the address' code size

EDIT: The function will return false if it is invoked from a contract's constructor (because the contract has not been deployed yet). The code should be used very carefully, if at all, to avoid ...
eth's user avatar
  • 86k
17 votes

Get public key of any ethereum account

It is now possible to recover public key from Ethereum transaction without any coding: Open the transaction in Etherscan.io Click on vertical ellipsis in the top-right corner Click on "Get Raw ...
Mikhail Vladimirov's user avatar
16 votes

How are ethereum addresses generated?

Private Key Space: Here are some code examples, based on the elliptic curve secp256k1 used by ethereum, as others have noted in order for the 256-bit key to be valid, it must be smaller than the ...
Steven Hatzakis's user avatar
16 votes

What is an 'EOA' account?

Ethereum accounts are generally of two types- Externally Owned Accounts Managed by Human Account creation incurs no cost Can transfer Ether (ETH) to other accounts, but cannot create smart contracts ...
Srajan Gupta's user avatar
16 votes
Accepted

How to explore all transactions for a given account?

If you want to build a explore like etherscan.io, you need to crawl all data in ethereum network and save all txs in the db. There is no direct rpc method to obtain all transactions related to the ...
rong jialei's user avatar
16 votes
Accepted

Unlock account permanently

Seems like you can unlock it for as long as the geth instance is running using a 0 as duration parameter: web3.personal.unlockAccount("address", "pass", 0);
Arko Elsenaar's user avatar
15 votes
Accepted

How to transfer the whole balance of an account?

No. You cannot send the entire balance because the fees are deducted from your account's balance, not from the value being sent. To sweep an account you need to send balance-gas*price ETH as the ...
Péter Szilágyi's user avatar
15 votes
Accepted

Execute transaction Approve directly against contract address (without ABI)

You will need the ABI. The .methods is an attribute of the contract instance, which you get by using the ABI. If you are using ethers.js, you can use a shorthand ABI to achieve the same goal: let ...
Shane Fontaine's user avatar
14 votes
Accepted

How can I get my accounts into metamask or vice versa?

You can now import single/"loose"(as we call) keys into MetaMask if you click the menu in the top right corner. It will drop down with the option "Import account", you can click that and it will take ...
frankiebee's user avatar
14 votes

How to transfer Ether between accounts in Solidity?

address.transfer() throws on failure forwards 2,300 gas stipend, safe against reentrancy should be used in most cases as it's the safest way to send ether address.send() returns false on failure ...
medvedev1088's user avatar
14 votes
Accepted

Why are smart contract outputs different from ordinary transactions?

Here's an intuition. The simplest transaction in Ethereum costs 21000 gas and looks like this: {from: '0x from', to: '0x to', value: web3.toWei(1, "ether")} When you're depositing to the exchange, ...
eth's user avatar
  • 86k

Only top scored, non community-wiki answers of a minimum length are eligible