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 ...
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 ...
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;
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.
...
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 ...
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) ...
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 ...
eth♦
- 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.
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 ...
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 ...
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 =...
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 ...
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
...
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:
...
eth♦
- 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 ...
eth♦
- 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"));
...
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 ...
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 ...
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 ...
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=...
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.
...
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(...
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 ...
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 ...
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, ...
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 ...
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:/...
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=...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
balances × 276solidity × 58
transactions × 49
go-ethereum × 37
tokens × 36
web3js × 34
erc-20 × 32
accounts × 31
ether × 29
contract-development × 20
addresses × 20
etherscan × 17
wallets × 14
synchronization × 10
remix × 9
payable × 9
the-dao × 9
blockchain × 8
json-rpc × 8
metamask × 7
mining × 7
contract-deployment × 6
javascript × 6
ethereum-classic × 6
internal-transactions × 6