88 votes
Accepted

How to get a contract's balance in Solidity?

You can do this by calling address.balance. To get the contract's balance, just do this.balance. Read the docs. Update: As of Solidity ^0.4.24, you need to do: address(this).balance (Copied from ...
user avatar
  • 2,277
40 votes

What are the pros and cons of Ethereum balances vs. UTXOs?

The main validation constraints in a Bitcoin UTXO system are: every referenced input must be valid and not yet spent the transaction must have a signature matching the owner of the input for every ...
user avatar
27 votes

How to get a contract's balance in Solidity?

Small update from my side: You want to use the following, address(this).balance;
user avatar
  • 711
24 votes

Why is my ether balance 0 in geth, even though the sync is nearly complete?

geth --fast has an interesting effect: geth cannot provide any information about accounts or contracts until the sync is fully complete. Try querying the balance again after eth.syncing returns false. ...
user avatar
  • 6,141
24 votes

How to get ETH contract balance with Ethers.js

getBalance is a function of the Ether.js blockchain provider object, it is used this way : const balance = await provider.getBalance("address"); Note that you can use contract.address to ...
user avatar
  • 3,857
21 votes
Accepted

Can a contract with no payable function have ether?

Yes, a contract can have Ether balance without any payable function. There are four ways how it's possible: selfdestruction. Another contract self destructs (by using the selfdestruct functionality) ...
user avatar
20 votes
Accepted

How does the Ethereum ETH accounting system work and prevent double-spends?

Each account has a globally accessible nonce which prevents same-chain replay attacks and double spends. The nonce is the sequence number, which miners check, because a block that has a transaction ...
user avatar
  • 78.9k
20 votes

How to get a contract's balance in Solidity?

As of Solidity ^0.4.24, you need to do: address(this).balance Find an example here.
user avatar
19 votes

How to programmatically detect and accept ETH and ERC20 deposits

It'd probably go something like this: User wants to deposit a token to your exchange If it's the first time the user is depositing that token then this occurs: Generate a new wallet key/pair on the ...
user avatar
  • 4,795
18 votes

How to retrieve the Contract account balance in web3 or in geth command line?

To check the balance you can do: web3.eth.getBalance(contract.options.address) Or: web3.eth.getBalance("0x045bfe22453a9ca06aff4bdc5d7f5870eba121bd") To transfer balance on a contract without ...
user avatar
18 votes
Accepted

Cant get address balance using web3js

The issue with your testnet url, https://ropsten.etherscan.io/ is not running eth client. Find below code to connect ropsten node. const testnet = 'https://ropsten.infura.io/'; const walletAddress =...
user avatar
14 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 ...
user avatar
13 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 ...
user avatar
  • 10.4k
11 votes

What are the pros and cons of Ethereum balances vs. UTXOs?

The accepted answer is a very good summary of the following wiki: https://eth.wiki/en/fundamentals/design-rationale#accounts-and-not-utxos See it for further details, including Ethereum's rationale: ...
user avatar
  • 78.9k
11 votes
Accepted

How to transfer Ether between accounts in Solidity?

A contract can read any balance using address.balance like: _buyer.balance A contract can send its Ether in units of wei using address.send like: seller.send(price) A contract cannot subtract from ...
user avatar
  • 78.9k
11 votes

Automatically update account balance with web3.js without polling

You can install a block filter and only update balances when a new block arrives. const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); ...
user avatar
  • 29.7k
10 votes

How does the Ethereum ETH accounting system work and prevent double-spends?

I am not providing an answer here but I am elaborating on a small discussion with @eth which is relevant to the OP's question, and I wanted to share what I have learnt, thanks to @eth and a bit of ...
user avatar
  • 1,165
10 votes

How are Ether balances stored on the Ethereum blockchain

The related question linked in comments by Richard Horrocks answers the question pretty well IMO. Here's what the Ethereum yellowpaper has to say about this (search for balance, it's hit number 2 ATM ...
user avatar
9 votes
Accepted

How can I get notification from geth when I receive ether?

personally I registered my addresses on https://etherscan.io that provides such a service, by email. If you really want to do it by yourself, the simplest I can think would be to register a cron job ...
user avatar
  • 4,550
9 votes

Etherscan API - Get all token balances

As previously mentioned it doesn't appear possible using etherscan. But it's possible using the (free) ethexplorer.io API. The format is: http://api.ethplorer.io/getAddressInfo/[YOUR_ADDRESS]?apiKey=...
user avatar
9 votes
Accepted

Getting Metamask account's balance using fromWei

Apparently, this is not the same inside the anonymous callback function you're passing to getBalance. Try replacing it with a fat arrow function, that binds the outer this value to the inner scope. ...
user avatar
  • 407
9 votes
Accepted

Truffle test: How to test Ether transfer? Balance of specific account?

To assert the balance of an account, try this: let expectedBalance = web3.toBigNumber(web3.toWei(3, 'ether')); let actualBalance = await web3.eth.getBalance(accounts[1]); assert.deepEqual(...
user avatar
  • 3,966
8 votes
Accepted

What are the balances of The DAO and it's child DAOs on the Ethereum Classic chain?

I'm using the same unmodified script from How many ethers have been drained through the recursive call attacks on The DAO? to calculate the balance of The DAO and it's child DAOs. For a finer ...
user avatar
8 votes

How to transfer Ether between accounts in Solidity?

Please refer to address methods documentation. You should prefer to use transfer over send: There are some dangers in using send: The transfer fails if the call stack depth is at 1024 (this can ...
user avatar
8 votes
Accepted

How can I list The DAO proposals and vote from the command line?

Yes. Here Is theDAOVoter Description theDAOVoter v1.0000000000000003 is a little Perl script (~808 lines, 738 source lines) that will allow you to: List The DAO proposals. List your accounts, ...
user avatar
8 votes
Accepted

How do I know how "confirmed" the result of calling getBalance API is?

getBalance With A Block Number You can pass in the block number as part of the parameter. Here is Kraken's address: 0x2910543af39aba0cd09dbb2d50200b3e800a63d2. Let's check what the latest block ...
user avatar
8 votes
Accepted

How does etherscan fetch the number of token holders from a smart contract?

They keep track of Transfer events emitted by that smart contract. Most likely they record them in an SQL database and maintain a ledger based on these events. The event is defined in the ERC20 https:/...
user avatar
  • 10.4k
8 votes
Accepted

API for ERC20 token balance - EtherScan

From https://etherscan.io/apis#tokens: Get ERC20-Token Account Balance for TokenContractAddress https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=...
user avatar
  • 26.7k
7 votes
Accepted

How do I print my account balances and TheDAO tokens from geth

getAllBalances Including TheDAO Tokens Here's a version of getAllBalances that also displays TheDAO tokens. The following shell script works in the Linux and Mac environments where you are already ...
user avatar
7 votes

How to get a contract's balance in Solidity?

In case of invalid opcode, use a local variable of type address payable as workaround: address payable self = address(this); uint256 balance = self.balance; In solidity 0.5.14, I get ...
user avatar

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