2

I'm aware of using the value field in Remix to include ETH with my function call transaction but is there a way to send another token with my transaction, for example, LINK?

Additionally I would like to require there's a certain amount of LINK sent, similar to require(msg.value == X) for ETH. I already have the token interface imported and initialized but am unsure where to go from there and don't know how to send the token in Remix to test it anyway.

import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/interfaces/LinkTokenInterface.sol";
LinkTokenInterface internal LINK;
//in constructor (kovan LINK token)
LINK = LinkTokenInterface(0xa36085F69e2889c224210F603D836748e7dC0088);

2 Answers 2

1

Sure, but the flow is a little counter-intuitive and takes some getting used to.

You can send ETH and/or data to a contract function. The data can instruct a contract function to seize a certain amount of a token from someone, usually the msg.sender (but not necessarily).

Your contract would use the ERC20, transferFrom(<funder>, <amount>) function. Since we can't have everyone just helping themselves to everyone else's money, the user first approves an allowance with the approve(<yourContract>, <agreedAmount>) function or the increaseAllowance() function.

e.g.

token = LinkTokenInterface(0xa36085F69e2889c224210F603D836748e7dC0088)
...
token.transferFrom(msg.sender, msg.value);
  • Alice => ERC20 "let the contract have my tokens"
  • Alice => contract "take my tokens"
  • contract => ERC20 "give me alice's tokens"

Hope it helps.

2

Think I found the answer actually: Call a smart contract payable function sending erc20 token

User/me first needs to call the approve function in the LINK contract then my Remix contract can transfer tokens from msg.sender to itself itself using LINK's transferFrom function.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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