when I call the getbal() of contract "Account" it shows 0 balance but when I call createacc() of contract "accountfactory" with value=30, accountfactory's balance becomes 9.but account balance shows 0. why? code link = https://pastebin.com/s3Y77VpD

  • Try to avoid pastebin, it's better to put the code here so that anyone can have all the required information to help you right here. That being said, I was about to edit your question to put the code, but line 14 is commented : // return address(this).balance; is it a typo or is it your actual code ?
    – hroussille
    Apr 14 at 13:44
  • @hroussille see this time i called createacc with value 31 but still not getting balance in Account contract and balance is 10 in accountfactory which is perfect but why balance is zero in Account. see = screenshot
    – Hitesh
    Apr 15 at 0:44

2 Answers 2


Strange, this

function getbal() public view returns(uint){
    return address(this).balance;

Is working fine for me, you have 2 getbal() functions are you sure you are calling the correct one. On line 14 one of them is commented out the other one one line 33 seems fine tho. Maybe delete the one on line 14 so you know its the right one. I dont see why it wont work then.

  • yes i am calling correct one but still not getting any value in Account contract why? screenshot
    – Hitesh
    Apr 15 at 0:48
  • @Hitesh it says your balance is 10, are you sending funds in wei. Apr 15 at 11:26

Your function is working perfectly, the screenshot you send is showing balance of 10 wei. You may be sending your values in wei not ether, with remix you can chage your unit type next to where you set the value amount hope this helps.

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.