0

When a contributor transfers fund to my smart contract the default balance is automatically increased. Is it possible to control this default property within our contract.

Also, will a method executed with a payable keyword effect the current balance property of that smart contract in any way?

  • what do you mean by "control this default property"?. a payable function is set to accepts ethers. – Badr Bellaj Aug 13 '17 at 8:02
  • What i meant here is that, how payable method automatically modifies my contract balance? To my understanding, this.balance is an internal property which i might not keep a check on every time. How are things executing behind it? – Gagan Aug 13 '17 at 8:40
0

Is it possible to control this default property within our contract.

No, this will always be the Ether balance of your contract (in Wei) but you could simply send those funds elsewhere via recipient.transfer(amountOfWeiToTransfer);

will a method executed with a payable keyword effect the current balance property of that smart contract in any way?

If that function got Ether, then it will increase this.balance unless you forward the exact amount via recipient.transfer(msg.value); which is common for a crowdsale as you can see, e.g. here in the OpenZeppelin library.

0

If you could control this.balance as you intend the system would be plainly broken as you could do this.balance = 1000 ether, generating ether balance in your contract out of thin air.

You might be confusing this.balance to a custom state variable mapping that you could have in your contract as balances["account"] that holds, for each user (or even the contract itself) the balance of your own token or the ETH your contract has received/sent for accounting purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.