0

I'm developing a DApp for Decentraland that will accept payments in their ERC-20 token MANA. How can I code a smart contract to accept a token other than Eth? How can msg.value know the value of a different token?

Also, how can I store MANA in the smart contract (as address(this).balance)?

1

address(this).balance and msg.value exclusively relate to ether, so you can't get those to somehow show you token amounts.

But to accept tokens, the caller needs to first call approve(<address>, <amount>) on the token, where <address> is the address of your contract, and <amount> is the number of tokens. Then when they call a function on your contract, you can call token.transferFrom(msg.sender, address(this), amount) to transfer the tokens to the contract. You can check the contract's token balance with token.balanceOf(address(this)). In those calls, token is the contract for the token you want to use.

  • Great, thanks for the info. – Steve Jun 17 '19 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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