I’m new to the smart contract world and there are many things that I still don’t get how works.
I’ve created a simple contract with the following methods:
constructor()
{
tokenCreator = msg.sender;
balances[tokenCreator] = TokenMaxSupply;
IUniswapV2Router02 uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
UniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
UniswapV2Router = uniswapV2Router;
}
/**
* @dev Returns the total supply of this token
*/
function TotalSupply() public view returns (uint256)
{
return TokenMaxSupply;
}
/**
* @dev Check the number of tokens owned by an address including holder reflections
*/
function CheckAddressBalance(address addressToCheck) public view returns (uint256)
{
return balances[addressToCheck];
}
/**
* @dev Check the allowance between addresses
*/
function CheckAllowance(address from, address to) public view returns (uint256)
{
return allowances[from][to];
}
/**
* @dev Transfers tokens from one address to another.
*/
function TransferTokens(address sendingAddress, address addressToSend, uint256 amount) public returns (bool)
{
require(addressToSend != address(0), 'Invalid Address.');
require(sendingAddress != address(0), 'Invalid sending Address.');
require(balances[sendingAddress] >= amount, 'Not enough tokens to transfer.');
//Decrease sender balance
balances[sendingAddress] = balances[sendingAddress].sub(amount);
//Add the new amount to receiver address
balances[addressToSend] = balances[addressToSend].add(amount);
emit Transfer(sendingAddress, addressToSend, amount);
return true;
}
My goal is to deploy the contract and add it to pancakeswap.
My question is: When someone wants to buy my token in pancakeswap, the method TransferTokens
should be called to add/subtract the tokens. How pancakeswap knows that it needs to call this function?
Or do pancakeswap calls a specific method and I need to change the name of the method?