简体   繁体   English

如何在一笔交易中结合 2 个智能合约功能?

[英]How can I combine 2 smart contract functions in one transaction?

I am building two smart contracts, one is casino contract and the other one is lottery contract(planning to deploy it separately).我正在构建两个智能合约,一个是赌场合约,另一个是彩票合约(计划单独部署)。 I want to combine both the placebet(casino) function and buyticket(lottery) function in one call.我想在一个电话中结合 placebet(casino) function 和 buyticket(lottery) function。 Once user would call placebet on casino contract, he will automatically buys lotteryticket also.一旦用户在赌场合约上调用 placebet,他也会自动购买彩票。 Any help will be appreciated.任何帮助将不胜感激。 Thank you.谢谢你。

Note: (Pls. respect) I am just a newbie, no formal coding education, I am just studying how to make dapp.注意:(请尊重)我只是一个新手,没有接受过正规的编码教育,我只是在研究如何制作dapp。

If I understand correctly, you need to make the first method call another method from another contract.如果我理解正确的话,你需要让第一个方法调用另一个合同中的另一个方法。

Here is an example:这是一个例子:

contract LotteryContract {
  function buyTicket() public {
    // code to buy ticket
  }
}

contract CasinoContract {
  function placeBet() public {
    // code to place bet
    LotteryContract.buyTicket()
  }
}

The basic idea in this example is that we call the LotteryContract's method in CasinoContract .这个例子的基本思想是我们在CasinoContract中调用LotteryContract's方法。 In this case, when the user makes a bid via the placeBet method, the contract will call another buyTicket method在这种情况下,当用户通过placeBet方法出价时,合约将调用另一个buyTicket方法

If you meant to make two calls to different contracts at once from the user, you can't do that.如果你打算同时从用户那里调用两个不同的合约,你不能那样做。 The user can only call one method from the contract, which will call other methods inside itself.用户只能调用合约中的一个方法,合约会调用自身内部的其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM