Fungible Token Deployment Error

Hello,

Am trying to deploy a Fungible Token smart contract but am getting the error below:
*node:10682) UnhandledPromiseRejectionWarning: Error: Http request for https://compiler.aepps.com/aci failed with status code 403. Status: Forbidden. *
Error data: {“reason”:“Type errors\nCannot unify bytes(1)\n and address\nwhen checking the application at line 59, column 31 of\n (!=) : (address, address) => bool\nto arguments\n spender : address\n #00 : bytes(1)\n\nCannot unify bytes(1)\n and address\nwhen checking the application at line 72, column 31 of\n (!=) : (address, address) => bool\nto arguments\n account : address\n #00 : bytes(1)\n\nCannot unify bytes(1)\n and address\nwhen checking the application at line 42, column 26 of\n (!=) : (address, address) => bool\nto arguments\n to : address\n #00 : bytes(1)\n\nCannot unify bytes(1)\n and address\nwhen checking the application at line 33, column 31 of\n (!=) : (address, address) => bool\nto arguments\n spender : address\n #00 : bytes(1)\n\nCannot unify bytes(1)\n and address\nwhen checking the application at line 65, column 31 of\n (!=) : (address, address) => bool\nto arguments\n spender : address\n #00 : bytes(1)\n”}

The issue seems to be this validation:
requireValidation(spender !=#0, “Invalid address”)

Any pointers please?

Old code? The code seem to use #0 as an address - this was a valid address literal in Sophia 2.1, but is not valid in Sophia 3 where address literals are ak_...

Hello hanssv,
Thank you but how do I do the validation on Sophia 3? Am new to Sophia unfortunately and I have a tight deadline.

I explained what the error was (using the old address literal format), and I explained what the new format should be, what else do you need?

Here is the documentation for Sophia literals: https://github.com/aeternity/protocol/blob/master/contracts/sophia.md#literals

2 Likes

Hi Hanssv,
Thank you for the support.
I have been struggling to have this working. Below are my tries. None of them works:

requireValidation(to !=ak_, “Invalid address”)
requireValidation(to !=#ak_, “Invalid address”)
requireValidation(to !=ak_…, “Invalid address”)

I will greatly appreciate your suggestion.

maybe take a step back from this issue, what would you consider “invalid address”? Address literals are typechecked in sophia, so you if your contract compiles and runs, there can be no “invalid address”.

1 Like

to help on your actual issue it would be good to know the full address of ak... that you did put in and of what type your to is.

1 Like

Hi Piwo,

I was using the below code from your dev documentation to create a fungible token.
Checkout the function Require.

contract FungibleToken =

  • record state = {*

  • owner : address,*

  • total_supply : int,*

  • balances : map(address, int),*

  • allowed : map((address,address), int)}*

  • public stateful function init() = {*

  • owner = Call.caller,*

  • total_supply = 0,*

  • balances = {},*

  • allowed = {}}*

  • private function lookup_by_address(k : address, m, v) =*

  • switch(Map.lookup(k, m))*

  •   None    => v*
    
  •   Some(x) => x*
    
  • public function total_supply() : int = state.total_supply*

  • public function balance_of(who: address) : int = lookup_by_address(who, state.balances, 0)*

  • public function allowance(owner: address, spender: address) : int =*

  • switch(Map.lookup((owner, spender), state.allowed))*

  •   None    => 0*
    
  •   Some(x) => x*
    
  • public stateful function transfer(to: address, value: int) : bool =*

  • transfer’(Call.caller, to, value)*

  • public stateful function approve(spender: address, value: int) : bool =*

  • require(value > 0, “Value is sub zero”)*

  • require(spender != #0, “Invalid spender address”)*

  • put(state{allowed[(Call.caller,spender)] = value})*

  • true*

  • private stateful function transfer’(from: address, to: address, value: int) : bool =*

  • require(value > 0, “Value is sub zero”)*

  • require(value =< balance_of(from), “Not enough balance”)*

  • require(to != #0, “Invalid address”) // prevents burning of tokens by sending to address 0. Technically is a valid request*

  • put(state{*

  •  balances[from] = sub(balance_of(from), value),*
    
  •  balances[to] = add(balance_of(to), value)})*
    
  • true*

  • public stateful function transfer_from(from: address, to: address, value: int) : bool =*

  • require(state.allowed[(from, Call.caller)] >= value, “Value is bigger than allowed”)*

  • put(state{allowed[(from, Call.caller)] = sub(state.allowed[(from, Call.caller)], value)})*

  • transfer’(from, to, value)*

  • true*

  • public stateful function increase_allowance(spender: address, added_value: int) : bool =*

  • require(spender != #0, “Invalid address”)*

  • put(state{allowed[(Call.caller, spender)] = add(state.allowed[(Call.caller,spender)], added_value)})*

  • true*

  • public stateful function decrease_allowance(spender: address, subtracted_value: int) : bool =*

  • require(spender != #0, “Invalid address”)*

  • put(state{allowed[(Call.caller,spender)] = sub(state.allowed[(Call.caller,spender)], subtracted_value)})*

  • true*

  • public stateful function mint(account: address, value: int) : bool =*

  • only_owner()*

  • require(account != #0, “Invalid address”)*

  • put(state{total_supply = add(state.total_supply, value),*

  •  balances[account] = add(balance_of(account), value)})*
    
  • true*

  • public stateful function burn(value: int) : bool =*

  • require(balance_of(Call.caller) >= value, “Burned amount is less than account balance”)*

  • put(state{total_supply = sub(state.total_supply, value),*

  •  balances[Call.caller] = sub(balance_of(Call.caller), value)})*
    
  • true*

  • private function add(a : int, b : int) : int =*

  • let c : int = a + b*

  • require(c >= a, “Error”)*

  • c*

  • private function sub(a : int, b : int) : int =*

  • require(b =< a, “Error”)*

  • a - b*

  • private function require(b : bool, err : string) =*

  • if(!b)*

  •  abort(err)*
    
  • private function only_owner() =*

  • require(Call.caller == state.owner, “Only owner can mint!”)*

What dev documentation? There is no token standard on aeternity yet

1 Like

He is probably referring to this:

1 Like

This documentation is quite outdated, did you try fixing it with the comments I did write above?