When getting contract's balance on Remix, it returns the correct answer. But when the same function is called with JS Test, it returns a lot of junk.

I referred to How to get a contract's balance in Solidity? but it does not work anymore or something is missing in my JS code.


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


it('should return contracts balance', async function() {
    let contractBalance = await this.auction.contractBalance()


TruffleConfig {                                                                                                                                                                                                    
  _deepCopy: [ 'compilers' ],                                                                                                                                                                                      
  _values: {                                                                                                                                                                                                       
    truffle_directory: '/home/satoshi/.nvm/versions/node/v12.13.1/lib/node_modules/truffle',                                                                                                                       
    working_directory: '/home/satoshi/auction',                                                                                                                                                    
    network: 'development',                                                                                                                                                                                        
    networks: { development: [Object] },                                                                                                                                                                           
    verboseRpc: false,                                                                                                                                                                                             
    gas: null,                                                                                                                                                                                                     
    gasPrice: null,                                                                                                                                                                                                
    from: null,                                                                                                                                                                                                    
    confirmations: 0,                                                                                                                                                                                              
    timeoutBlocks: 0,                                                                                                                                                                                              
    production: false,                                                                                                                                                                                             
    skipDryRun: false,                                                                                                                                                                                             
    build: null,                                                                                                                                                                                                   
    resolver: TestResolver {                                                                                                                                                                                       
      resolver: [TestResolver],                                                                                                                                                                                    
      source: [TestSource],                                                                                                                                                                                        
      search_path: '/tmp/test-202034-9962-wwsk5l.xcbo',                                                                                                                                                            
      seen: [],                                     
      require_cache: {},                            
      cache_on: true                                

1 Answer 1


Use await this.auction.contractBalance().call().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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