我可以在LIGO的另一个智能合约中创建一个Tezos智能合约吗?



通过父合约,我希望能够创建多个子合约。我如何在LIGO中做到这一点?

查看代工厂示例:https://ligolang.org/docs/tutorials/inter-contract-calls/inter-contract-calls/#contract-factories

他们使用的代码可以在这里找到:https://gitlab.com/ligolang/ligo/-/blob/dev/gitlab-pages/docs/tutorials/inter-contract-calls/examples/contracts/ligo/CreateAndCall.ligo

不幸的是,Tezos.create_contract在实践中并没有很好地工作。只有在子契约非常简单的情况下才有效。子代码必须完全在Tezos.create_contract调用中编写,或者它使用的所有定义都必须是[@inline]'d。如果不是所有定义都内联,您将得到有点神秘的错误&;不是所有自由变量都可以在Tezos中内联。create_contract用法!">

在未来的Ligo版本中应该提供更好的替代方案。希望soon-ish。

同时有一个解决方案:单独编译您的子合同,并使用内联%MichelsonCREATE_CONTRACT,可能使用#include来包括编译的。tz文件。以下是Cameligo中的示例:

type child_storage = unit
type create_contract_args =
[@layout:comb]
(* order matters because we will cross the Michelson boundary *)
{ delegate : key_hash option;
balance : tez;
storage : child_storage }
type create_contract_result =
[@layout:comb]
{ operation : operation;
address : address }
[@inline] let create_contract =
[%Michelson ({|{ UNPAIR 3;
CREATE_CONTRACT
#include "./child.tz"
;
PAIR
}|} : create_contract_args -> create_contract_result)]
let main (_ : unit * unit) : operation list * unit =
let {operation; address = _} =
create_contract { delegate = (None : key_hash option);
balance = Tezos.get_amount ();
storage = () } in
([operation], ())

相关内容