We can send a er20 token to a smart contract.

To track it we can use a function ( msg.value is always wei )

But how do i verify if the erc20 token is actually sent ?

For example i want to set map true if the person sent > 5 vbcoins

function sendVBCoins(uint256 _howmuch){
  require(_howmuch >= 5);
  goodperson[msg.sender] = true;

Anyone can send 1 wei and call that function and become goodperson.

How do i solve it ?

1 Answer 1


This sort of transfer can be done in two stages.

The person who aspires to be good needs to first call vbToken.approve(<your contract's address>, 5) (or rather 5 * 10**decimals). This authorizes your contract to take 5 vbcoins from them.

They then call sendVBCoins(5) (or, again, more likely 5 * 10**decimals). Inside sendVBCoins, you will call vbToken.transferFrom(msg.sender, _howmuch). If that succeeds, then you've received those vbcoins from them, and you can consider them to be a "good person."

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.