1

Let's say we have a non-native contract. Whenever we call transfer()/send() or directly manipulate via balanceOf, how do we know which token (either native or non-native token) will be transferred?

I came across this from looking at this scam contract's decompiled source code. Obviously I didn't see any import of IERC20 or anything, or decompilation probably won't include them ?

Such decompiled code works with STPT token, and it's on BSC network. As I looked in the code, and transactions, I came to conclusion that balanceOf works against STPT token. But how can we know this when looking at the code alone without checking elsewhere?

As we have multiple ways to transfer as follows

  • payable(addr).transfer(amount) - I knew this from here that this is meant to transfer native token
  • transfer() and send() - I believe the developer needs to know such that the variable that calls this method needs to be based upon IERC20 or others ?
  • balanceOf() - I'm not sure about this...

Please feel free to correct me, go in depths or link me articles to read more on this stuff. Thank you very much in advance.

1 Answer 1

3

The methods (payable address).transfer() or (payable address).send() inside a smart contract is about transfering the native coin of the blockchain from the smart contract to the defined (payable address). In Ethereum, it will transfer Ether. In BsC, it will transfer BNB.

5
  • Hey thanks! So if I just address.transfer() or address.send(), then always it means we transfer non-native token right? Because from my understanding, non-native token would have a separate contract.
    – haxpor
    Commented Feb 16, 2022 at 17:10
  • I don't know what you mean by non-native token. If you are on ethereum, address.transfer() and address.send() will transfer Ether, always. =) Commented Feb 16, 2022 at 19:05
  • Non-native I mean non-ETH. I'm doubt address.transfer() and address.send() would always send Ether. What if such address is non-ETH, but another token contract.
    – haxpor
    Commented Feb 16, 2022 at 20:10
  • No problem. I also got a confirmation in SCP group. So if I have ERC20 address, if use address.transfer() it will transfer such ERC20 token (not ETH). But if I want to transfer ETH to such address, then I will do just like your answer payable(address).transfer(). Thanks again!
    – haxpor
    Commented Feb 16, 2022 at 20:22
  • 3
    I think they gave you the wrong answer. See, if you use (address).transfer you are transfering Ether, even if address is the account of a contract. You can send Ether for External Accounts and also to ERC20 Token accounts. When you have the instance of a smart contract which have a transfer function, then you can use (instance of the contract).transfer() to call the transfer function. Be aware of this difference. One thing is an address, other is the instance of a contract. The name of the function is the same, but only the name. Commented Feb 17, 2022 at 2:57

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.