3

When we have an Ink! smart contract code calling a chain extension, how do we receive this information from within the chain extension:

  1. The calling smart contract address/ID
  2. The original caller of the smart contract (or is this possible?)
  3. The equivalent EVM msg.value in the smart contract, if there is one?

If there is any tutorial/example that covers the above questions, it will be great just to paste the link out as well.

Thanks.

2
  • Are you talking about a chain extension? Apr 7, 2022 at 8:50
  • Yes, using #[ink::chain_extension] and #[ink(payable)] as mentioned in the doc
    – Jimmy Chu
    Apr 7, 2022 at 10:43

1 Answer 1

3

These environmental information is available to the ChainExtension through the Environment::ext() function. An instance of Environment is passed to ChainExtension::call() as a parameter.

The ext() function returns a type that implements Ext. Check out the linked documentation for the available functions.

To answer your question:

  1. env.ext().caller()
  2. We don't provide this functionality on purpose because basically every use of this information constitutes a security problem on Ethereum. We have env.ext().caller_is_origin(), though.
  3. env.ext().value_transferred()
1

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.