【问题标题】:Is there any way to limit execution of smart contract only to my dapp?有没有办法将智能合约的执行仅限于我的 dapp?
【发布时间】:2017-11-12 10:13:10
【问题描述】:

我的 dapp 将从客户端获取一些数据并将其发送给合约。我想避免欺骗它。

【问题讨论】:

    标签: blockchain ethereum solidity smartcontracts


    【解决方案1】:

    使用Modifiers

    pragma solidity ^0.4.0;
    
    contract MyContract {
      address mAdmin;
    
      modifier adminOnly {
        if (msg.sender == mAdmin) _;
      }
    
      function MyContract() {
        mAdmin = msg.sender;
      }
    
      function doSomething() adminOnly {
        ...
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 2020-06-09
      • 2012-11-14
      • 1970-01-01
      • 2019-01-10
      相关资源
      最近更新 更多