0

i have created an ERC20 token. i want to send some tokens to anyone who send ETHER to the contract using fallback payable method.

  1. how to set token price against ETHER.
  2. receive ETHER and send tokens using fallback payable function. solidity 0.6.
0

you would want to execute an erc20 transfer from your contract's erc20 balance to the person sending the ether. Inside your payable function you will want to have something like this:

// msg.value will have the value amount of the ether sent
// msg.sender will hold the value address of the person sending the ether

yourERC20Instance.transfer(msg.sender, tokenAmount);

You could do all the math you want to come up with the tokenAmount you want to exchange for the ether amount.

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.