![](/img/trans.png)
[英]I am trying to test this liquidity smart contract code but if shows error. Liquidity is similar to ocaml, tezos's smart contract language.
[英]Can I create a Tezos smart contract from inside another smart contract in 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 版本中应该提供更好的替代方案。 希望很快。
同时有一个解决方法:单独编译你的子合约,并使用内联%Michelson
和CREATE_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], ())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.