Circular Developer Docs
BuildNetworkGuidesConceptsStandards & ResourcesResources
  • Overview
  • Developer Guides
    • Get Started
    • Install Circular
  • Your first dApp on Circular
    • Introduction to Hyper Code IDE
      • Smart Contract Project Files
      • Project Files
      • CRC_Contract
      • Contract Method
    • Smart Contracts
      • Creating your first smart contract
      • Debugging
      • Deployment
      • Smart Contract Interaction
    • Wallet Access
      • Circular Wallet Architecture
      • Native CRC Wallet
      • Custom Wallet Data
    • Your First Token
      • Simple Token Balance
      • GetBalance Function
      • Drop Function
      • Transfer Function
    • Hyper Code Libraries
      • sha256.hc
      • secp256k1.hc
      • StrUtil.hc
  • Smart Contracts on Circular
    • Smart Contracts (Hyper Code)
      • Get Started
      • Why Hyper Code
      • Compiling
      • Testing
      • Debugging
Powered by GitBook
On this page
  1. Your first dApp on Circular
  2. Your First Token

GetBalance Function

Of all the Smart Native Contracts (SNCs) we’ve discussed, one stands out for its smart contract interaction: “GetBalance.” This endpoint retrieves the balance of a specific wallet. Its implementation is similar to the constructor, with the key difference being that we’re only fetching the wallet’s balance. Here’s the code for this operation:

__GetBalance: function (address) {
    
      // Creates a new wallet instance
      var wallet = Object.create(CRC_Wallet);
    
      // Opens the specified wallet
      if(wallet.OpenWallet(address)){
        
          // if the wallet is available prints out the balance
          println('Balance : ' + wallet.Balance + ' '+ this._Symbol);
          return wallet.Balance;
      }
      return -1;
  }

The code is simple: after creating an instance of the specified wallet, we check if it opens successfully, retrieve the balance, and print the result. We don’t need to close the wallet here, as no updates are made. Even if a “CloseWallet” operation were included, it would be ignored since Smart Native Contracts (SNCs) don’t modify the smart contract’s state.

PreviousSimple Token BalanceNextDrop Function

Last updated 7 months ago