Contract Address as parameter

Hello All,

I want to pass a contract address as parameter to a function in sophia.
but address only access account address and not contract addresses.

Somewhere in the community I read we can use the keyword contract literal inplace of address. But, it’s not working for me. I am getting an exception, Unexpected token 'contract'.

NOTE: I am testing the contracts on my local(macos) with aeternity javascript sdk version - 4.0.0.

3 Likes

I can see that the official documentation of aeternity sophia lang confirms that to pass contract address as a parameter to a function, we should use the literal contract.
https://aeternity.com/aesophia/v6.1.0/sophia_features/#literals

But this simply doesn’t work.

2 Likes

Hi @Jkrish1011

What you see at https://aeternity.com/aesophia/v6.1.0/sophia_features/#literals is the type contract literals which Sophia knows to handle, not the keyword contract.

From what I understand what you want to know is how de specify to some arbitrary contract to accept parameters of some other contracts.

For example, If you have a contract named MyContract and you have another contract that has an entrypoint expecting as parameter a MyContract address, you simply have to set the type of the parameter as MyContract.
Let’s say you have:
entrypoint my_function(the_contract_address: MyContract) = ....

Do not forget to have MyContract definition included in the contract file that needs it
include './MyContract.aes'

in the javascript side, you just have to call the function with the contract address

contractInstance.methods.my_function('ct_Ez6MyeTMm17YnTnDdHTSrzMEBKmy7Uz2sXu347bTDPgVH2ifJ')

5 Likes

do you mean @aeternity/aeproject? @aeternity/[email protected] is too old, the last one is 12

2 Likes

HI @davidyuk , thanks for notifying.
my @aeternity/aeproject is version 4.

2 Likes