【问题标题】:Transaction From Ethereum Smart contract [closed]来自以太坊智能合约的交易[关闭]
【发布时间】:2021-07-18 15:35:39
【问题描述】:

当我们有合约时,我们转移货币

签名是怎么做的???

例如,我向合约发送 10 个以太币,合约分给 5 个人

这个交易是什么样的?我的私钥从哪里来签署所有 5 笔交易?

【问题讨论】:

    标签: cryptography ethereum cryptocurrency ether


    【解决方案1】:

    我向合约发送 10 个以太币,合约分给 5 个人

    所以可能是这样的:

    pragma solidity ^0.8;
    
    contract MyContract {
        function redistribute(address[5] memory otherPeople) external payable {
            for(uint i = 0; i < 5; i++) {
                payable(otherPeople[i]).transfer(msg.value / 5);
            }
        }
    }
    

    您向合约发送一笔交易(价值 10 ETH),执行redistribute() 函数。

    合约执行 5 次内部交易,有效地将 2 ETH 转移到每个otherPeople 地址。

    在这种情况下,您只需要使用“主”交易发送者的私钥,因为其他交易是内部 tx,由主 tx 包装。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-07
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多