0

I have a test token (ERC20) deployd on ETH test network (Kovan) The token was deployed using Unicrypt tool So far everything ok, but the issues is how can i transfer tokens from an outside smart contract.

The token distribution is now (example):

Owner - 100

AddressA - 25

AddressB - 15

AddressC - 10

I'm trying to deploy a smart contract (for example just to set a number on the blockchain) but to do this the person setting the number must "pay" a token. So if AddressC wants to set the number 55, must "pay" 1 token (balance for AddressC after will be 9), the smart contract (not the ERC20 SmartContract) must be able to transfer 1 token from AddressC into the Owner (Owner balance will become 101)

How can i achieve this, or is there any other (perhaps) better way to achieve this ?

PS: Basically how can i have a token (ERC20) and use it on "custom actions" outside the ERC20 SmartContract

Regards

1 Answer 1

0

Read about the ERC20 approval mechanism.

First the user would need to approve your "set numbers" contract to spend the ERC20 token that the user owns.

Then the user would call the "buy" function of "set numbers" which will pull the token from the user to your contract.

2
  • hi..thanks...but is there any other way around that ? (without the approve) Oct 27, 2021 at 15:49
  • Hmm... If you're the one deploying the ERC20 token, you can have it call your "set numbers" contract when somebody is transferring it to your "set numbers" contract for example... but that is quite unusual behaviour. The problem is that unlike sending ETH, basically your contract can't know when somebody transferred a token to it. And your contract can't pull the token without the user approving it first. Oct 27, 2021 at 15:55

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.