Hello,
Is it possible to pass contract address as a parameter in a function of another contract?
I’m experiencing an error while trying to deploy a contract through forgae.
Thanks
Hello,
Is it possible to pass contract address as a parameter in a function of another contract?
I’m experiencing an error while trying to deploy a contract through forgae.
Thanks
Yes it is possible, what is the code you use and error you experience?
I am trying to deploy a contract with an init parameter address (e.g. ct_EkfKw779YedZs9Z1vfN4wMirwFVaxBeB72uGc92dkMTJAhjUm)
Example of a contract:
contract Car =
record state =
{
cm: address }
entrypoint init(cm: address) : state = {
cm = cm }
Error is:
Error data: {“reason”:“Type errors\nThe type address is not a contract type\nwhen checking that the contract literal at line 62, column 92\n ct_EkfKw779YedZs9Z1vfN4wMirwFVaxBeB72uGc92dkMTJAhjUm\nhas the type\n address\n”}
As the error message says:
it needs to be contract instead of address cm: contract
, if it stats with ak_
it is address, if it starts with ct_
it is contract.
See the sophia literals documentation protocol/contracts/sophia.md at master · aeternity/protocol · GitHub
If you follow the documentation as calling other contracts, you wont even need the contract or address literals, as passing the ct_
contract address is directly perceived as instance of the contract if its interface is defined: protocol/contracts/sophia.md at master · aeternity/protocol · GitHub
Well, using the ‘contract’ literal does not even allow me to compile it, stating: “Error data: {“reason”:“Parse errors\nline 4, column 8: Unexpected token contract”}”
There is no generic contract
type it has to be explicit. Here is an example of a contract that has another contract in its state and call that contract - the type of that other contract is Other
and the literal passed to init
should be ct_...
:
contract Other =
entrypoint get : () => int
entrypoint tick : () => ()
contract Test =
record state = { other : Other }
entrypoint init(another_contract : Other) = { other = another_contract }
entrypoint increment() = state.other.tick()
entrypoint get() = state.other.get()
Thank you for the clarification @hanssv.chain, I did never try using contract
as literal, was just assuming it works from documentation.