0

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?

1 Answer 1

0

It is the latter.

Your contract must absolutely conform to the ERC20 standard. You cannot use a function such as your TransferTokens function.

Pancakeswap (and pretty much everyone else also), will call the functions defined in ERC20. Custom functions not part of ERC20 will never be called.

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.