1

I´m trying to write a function that returns the balance of the account where the contract is deployed.

Something with the following form:

pub fn get_balance(&self) -> Balance { env::account_balance() } 

The above code returns the balance of the account that is calling the method, the signer. Is there a way to make it returns the balance of the contract account?

1 Answer 1

1

I got the answer. near_sdk:env::account_balance() already do what i was looking for. It retrieves the balance of the contract account.

I was lacking a way to check it properly. To do it, i used near state [account_name] on the cli to verify if the balance returned was the master or subaccount (where the contract was deployed) balance.

So the answer would be:

pub fn get_balance(&self) -> Balance { env::account_balance() } 

noting that to have the transferible balance, it would have to take into account the min balance used for storage.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.