1

Do anyone mind explaining the approve and allowance functions in this token smart contract:

export function approve(spender: string, tokens: u64): boolean {
  logging.log("approve: " + spender + " tokens: " + tokens.toString());
  approves.set(context.sender + ":" + spender, tokens);
  return true;
}

and

export function allowance(tokenOwner: string, spender: string): u64 {
  const key = tokenOwner + ":" + spender;
  if (!approves.contains(key)) {
    return 0;
  }
  return approves.getSome(key);
}

I'm trying to make sense of what them are doing against the blog post I read about the ERC-20's approve and allowance functions from Cointelegraph

Not really, because [approve] checks a transaction against the total supply of tokens. It makes sure that there are none missing or extra. Another way to safeguard the integrity of our hypothetical poker game is to make sure no one brought extra BLU to the table. So, [approve] allows the exchange by checking that the total number of BLU on the table equals 10.

Like I said earlier, it won't hurt to include a little documentation in the token smart contract existing in this repo. Please!

1 Answers1

1

Approve function sets the number of tokens a contract is allowed to transfer from an owner.

Allowance grants to a 3rd party permission to use the owner's tokens. That being said, it doesn't mean the ability of someone else to steal your money, but you're allowing smart-contract to use them on your behalf.

d3mage
  • 99
  • 1
  • 9