4

Is there a specification somewhere which explains how to compute a human-readable address of a contract?

In order to originate a contract I need to provide its code, initial storage value and some other data and then I'll get its address. How is it computed?

4

When your originate a contract, you send an "operation" to the network. This operation is then serialized into byte format and a hash is derived - this is the operation hash for the given operation.

If an operation generates a new contract, you can manually calculate the new KT1 address by hashing the operation hash + an index byte (starting from 0). We use an index as some operations originate multiple new KT1 addresses. This is how eztz does it: https://github.com/TezTech/eztz/blob/master/src/main.js#L751

I'm unsure why you need this though - you don't need to know the new address before originating?

3
  • 1
    Thanks. So it's only possible to compute address of originated contract, right? I am asking because I am writing an interpreter of Michelson and there is ADDRESS instruction. It always returns address of a contract (not option value). Does it imply that it's impossible to put a contract on stack if this contract hasn't been originated? I made an experiment using ./alphanet.sh client run script. I computed address of SELF and PACKed. Then passed those bytes to another script and succesfully UNPACKed them. But this contract is not originated. How does it work? – Ivan Gromakovskii Feb 12 '19 at 13:09
  • 1
    Also which operations can originate multiple KT1 addresses? I found the following operations in the spec: CREATE_CONTRACT, CREATE_ACCOUNT, TRANSFER_TOKENS and SET_DELEGATE. As far as I understand, the first one originates 1 KT1 address and other operations don't generate KT1 addresses at all. – Ivan Gromakovskii Feb 14 '19 at 16:16
  • Also which hashing algorithm is used? Is it blake2b both times? – Ivan Gromakovskii Feb 15 '19 at 14:18

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.