4

I am developing a dapp where I need the public key of an address of the user, is it possible to get the public key in the contract (using SmartPy)? Or even on the client side using taquito or any other library?

4 Answers 4

5

It is not possible to do from inside a contract. But you can use the following RPC:

https://tezos.gitlab.io/alpha/rpc.html#get-block-id-context-contracts-contract-id-manager-key

Example:

https://florencenet.smartpy.io/chains/main/blocks/head/context/contracts/tz1aWXP237BLwNHJcCD4b3DutCevhqq2T1Z9/manager_key

3
  • Hi, thanks for the answer. The above link only gives me the public key for the manager, right? And not of the users, right?
    – illusion
    Jul 15, 2021 at 16:36
  • tz1, tz2, tz3 are implicit accounts. And manager_key is their public key, where the tz* address is the hash of the public key. Jul 15, 2021 at 16:42
  • Right, I got a lil confused...
    – illusion
    Jul 15, 2021 at 16:57
5

In the contract, you cannot obtain the public key from an address but if you are given both the public key and the address you can check that the public key corresponds to the address. In Michelson, assuming you have the address and the public key at the top of your stack this is done with HASH_KEY; IMPLICIT_ACCOUNT; ADDRESS; COMPARE; EQ.

In the client, you can use the RPC linked in @rodrigo-quelhas' answer but it will only work if the public key for the account has been revealed on chain. Usually revelation is done just before the first transfer from the implicit account.

0

It is possible to do so using tzkt API https://api.tzkt.io/#operation/Accounts_GetByAddress

I think its the easiest method use this https://api.ghostnet.tzkt.io/v1/accounts/{address}

0

On the client side with Taquito, there is getManagerKey() function in @taquito/rpc package to get it from rpc node. Here is the typedoc for your reference. Also, note that an address is the hash of a public key, it shouldn't be reversible by computation. So it only works for the address already revealed on a chain and the rpc node provides mapping.

Your Answer

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

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