Search code examples
pact-lang

How to get the sender address using Pact?


When using solidity I can get the sender address by using msg.sender and when using ink smart contracts I can use Self::env().caller();

Can anyone advise what the equivelent would be for Pact? I've had a look at some of the documentation but I think I must be missing it.

Appreciate any guidence you can give.

Thanks, KB


Solution

  • (chain-data) is a function that returns some metadata of your transaction. It's documented in the Pact language reference: https://pact-language.readthedocs.io/en/latest/pact-functions.html#chain-data

    You can get the sender value from the function like this:

    (at 'sender (chain-data))