title: Why my Solidity Ethereum Contract ran out of gas?
body: <p>truffle migrate --reset</p>
  <h1>Compiling your contracts...</h1>
  <blockquote>
  <p>Everything is up to date, there is nothing to compile.</p>
  </blockquote>
  <h1>Starting migrations...</h1>
  <blockquote>
  <p>Network name:    'development'
  Network id:      5777
  Block gas limit: 672197500 (0x2810eb7c)</p>
  </blockquote>
  <h1>1_initial_migration.js</h1>
  <h2>Replacing 'Migrations'</h2>
  <blockquote>
  <p>transaction hash:    0xf41feee2b768ba375d95ded5c40a48e7af3d59554f616738102a2a9805824d77
  Blocks: 0            Seconds: 0
  contract address:    0xe75Ea4aDD9728c9846778a695cE0CF32b66C1c52
  block number:        1
  block timestamp:     1621246185
  account:             0x33b005e2f8d83120b4ab4bDde1bD7Ad704077801
  balance:             99.99626098
  gas used:            186951 (0x2da47)
  gas price:           20 gwei
  value sent:          0 ETH
  total cost:          0.00373902 ETH</p>
  </blockquote>
  <blockquote>
  <p>Saving migration to chain.
  Saving artifacts</p>
  </blockquote>
  <hr />
  <blockquote>
  <p>Total cost:          0.00373902 ETH</p>
  </blockquote>
  <h1>2_deploy_contracts.js</h1>
  <h2>Replacing 'CryptoBoys'</h2>
  <p>Error:  *** Deployment Failed ***</p>
  <p>&quot;CryptoBoys&quot; ran out of gas (using a value you set in your network config or deployment parameters.)</p>
  <ul>
  <li>Block limit:  672197500 (0x2810eb7c)</li>
  <li>Gas sent:     6721975 (0x6691b7)</li>
  </ul>
  <p>When I wrote this function it caused the above mentioned error</p>
  <pre><code>    function getAllTokensMintedByUser(address user) public view returns(CryptoBoy[] memory result){
          
          uint256 k=0;
          result=new CryptoBoy[](totalMintedTokens[user]);
          if(totalMintedTokens[user]!=0){
              for(uint256 i=1; i&lt;=cryptoBoyCounter; i++) {
              
              CryptoBoy memory cryptoboy=allCryptoBoys[i];
              if(cryptoboy.mintedBy==user){
                result[k]=cryptoboy;
                k++;
              }
            }
          }
          
          return result;
        }
  </code></pre>