Zero address literal

What I got from digging through the compiler changes is that address literals no longer support #0 for zero address, it gives me the compilation error of type missmatch (address VS bytes(1) ). What would you recommend using now?

If you really want to have address “zero” (i.e. 32-bytes of zeros) you should use ak_11111111111111111111111111111111273Yts which is the proper encoding of this address.

But why would you want to use this address?! You can spend tokens to it, but that is effectively burning them? You can also compare it with another address, but there are 2^255 other addresses that you could also compare with; the zero address is not special?! I know there are a lot of weird constructions in early Sophia examples, but Sophia is typed and if you got something of type address it will be an address, no point checking if it is “> 0”, etc…

1 Like

I guess people just like to burn tokens from time to time :slight_smile:

1 Like

We are talking about your official code examples, which do not compile anymore. It would be great if you could provide an example of best practices you suggest, which would substitute such code.
Ex. require(owner == Map.lookup_default(token_id’, state.map_token_owner, #0), “Only token owner can transfer!”)

Thanks for you input

Can you link to that example?

It’s pretty much every contract, here take a look at this one
https://github.com/aeternity/aepp-sophia-examples/blob/master/libraries/FungibleToken/contracts/fungible-token-capped.aes

this contract is oudated for the last 2 hardforks, it did work in very early version of aeternity, but is not current any more.

Exactly, I’m interested in even fixing it and I’m asking you guys about what best practice do you recommend now after the changes

there is no updated best practice, there is no need for the zero address check any more

OK, so just to be explicit, in one of the previous examples

require(owner == Map.lookup_default(token_id’, state.map_token_owner, #0), “Only token owner can transfer!”)

How would you write it now?

maybe require(Some(owner) == Map.lookup(state.map_token_owner)) but it really depends on the remaining implementation.

Is there a specific reason you focus on the outdated token implementation?

There is a newer proposal for a token standard: AEX 9 - Fungible Token

2 Likes

lookup can give you a None, so maybe the opposite could work better in this case
owner == Some(Map.lookup(token_id', state.map_token_owner))?
Eather way, a lot of code is running around which is outdated, which I do believe to be an issue, since it’s already not that easy getting the grip of the AE ecosystem and Sophia.
Thanks for the link, I’ll check that contract out as well

owner == Some(Map.lookup(token_id', state.map_token_owner))

in this case owner is of type address while your comparison is option(option(address)) which is not comparable, this is why I was suggesting to wrap owner in Some() to compare types option(address) == option(address)