title: How to exploit this simple Smart Contract?
body: <p>I have been trying a lot of ways of exploiting this simple token contract written in Solidity for the Ethereum blockchain; yet, I am unable to successfully do so.</p>
  <pre><code>pragma solidity ^0.8.2;
  
  contract SimpleToken{
  
  mapping(address =&gt; uint) public balances;
  
  function buyToken() payable public {
      balances[msg.sender]+=msg.value / 1 ether;
  }
  
  function sendToken(address _recipient, uint _amount) public {
      require(balances[msg.sender]!=0); // You must have some tokens.
      balances[msg.sender]-=_amount;
      balances[_recipient]+=_amount;
      }
  }
  </code></pre>
  <p>I have been able to achieve such exploitation by sending transactions to the sendToken() function, but I am trying to write a contract that serves as the Exploit code for it.</p>
  <p>Here is what I have tried:</p>
  <pre><code>pragma solidity ^0.8.2;
  
  import &quot;./vuln.sol&quot;;
  
  contract Exploit {
      
      function buyPoisoned() payable public {
          SimpleToken t = new SimpleToken();
          t.buyToken{gas: 50000, value: 10}();
      }
  
      function exploit(address recpt, uint amount) public {
          SimpleToken t = new SimpleToken();
          t.sendToken{gas: 50000}(recpt, amount);
      }
  }
  </code></pre>
  <p>I have also tried with prior versions of the Solidity compiler (0.4.2 to be more precise), and yet I was unable to succeed.</p>
  <p>I do not know what I am missing to make it work.</p>
  <p>Thanks in advance for the help!</p>