I want to make a smart contract, where you can instantly swap your Ether to ERC20 token.
What I do have now:
pragma solidity >=0.4.16 <0.7.0;
contract Swap {
address owner;
address constant tokenAddress = address(
0x14eb2ab8e6d09000a98e3166b3cc994375071f69 //ERC20 token address
);
uint8[] validTokenAmounts = [2, 16, 32];
uint256 constant tokenPrice = 75000000000000;
function isTokenAmountValid(uint8 tokenAmount) private view returns (bool) {
for (uint8 i; i < validTokenAmounts.length; i++) {
if (tokenAmount == validTokenAmounts[i]) {
return true;
}
}
return false;
}
function swap(uint8 amount) public payable {
require(
msg.value >= amount * tokenPrice,
"You sent incorrect amount of Ether"
);
??transfer()?? // Here I don't know what how to send ERC20 tokens
}
}
I have a second question too - how do I deploy contract with XXX amount of ERC20 tokens in smart contract? It's my first time with smart contracts, I hope you will find time to help me.
Thanks :)