In tezos, I am able to get the tezos address starts with tz1 from the public key but I am unable to get the correct KT address. 

I am using this code from github.https://github.com/TezTech/eztz/blob/master/src/main.js#L768 

What is operationHash and ind? there is no comment to explain this.  Is operationHash publicKey in edpk format or some other hashing?

  hash : function(operationHash, ind){
    var ob = utility.b58cdecode(operationHash, prefix.o), tt = [], i=0;
    for(; i<ob.length; i++){
    tt = tt.concat([
     (ind & 0xff000000) >> 24,
     (ind & 0x00ff0000) >> 16,
     (ind & 0x0000ff00) >> 8,
     (ind & 0x000000ff)
    return utility.b58cencode(library.sodium.crypto_generichash(20, new Uint8Array(tt)), prefix.KT);

Is there any npm package available which do this?



1 Answer 1


KT addresses are the addresses of smart contract (aka. "originated accounts"). Contrary to tz addresses (aka. "implicit accounts"), smart contracts are not associated with a pair of cryptographic keys because there is no secret place at which they could store a secret key.

As the name "originated account" suggests, the existence of a smart contract starts at its origination operation. More precisely, the KT address is derived from the hash of the origination operation and a simple counter (ind in the code you quote, it is called "origination index" in the code of the protocol file contract_repr.ml) that guarantees that several smart contracts originated in the same operation have distinct addresses.

Here is the documentation from the protocol (file contract_repr.mli):

Originated contracts handles are crafted from the hash of the operation that triggered their origination (and nothing else). As a single operation can trigger several originations, the corresponding handles are forged from a deterministic sequence of nonces, initialized with the hash of the operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.