【问题标题】:How to create contracts on Ethereum block-chain in python?如何在 python 中在以太坊区块链上创建合约?
【发布时间】:2016-12-22 20:38:26
【问题描述】:

我想在以太坊上创建合约来存储数据。我是这个领域的初学者......我们有更好的解决方案吗?

在这个post,有人告诉我下载一个插件。这是一种方法,但我想用 python(或其他语言)在区块链中插入数据。

我不知道从哪里开始...下载以太坊?创建一个帐户?

会产生任何费用吗?多少钱?

如果合约可以更新,我可以使用以太坊合约来证明工作吗?

【问题讨论】:

    标签: python storage blockchain ethereum


    【解决方案1】:

    我不知道从哪里开始...下载以太坊?创建一个帐户?

    1. 安装命令行工具。 ethereum.org/cli

      我不建议从 pyethapp (Python) 或 eth (C++) 客户端开始。使用 geth (Golang) 或 parity (Rust)。它们很容易上手并且有据可查。

    2. 创建一个 hello world 合约。 ethereum.org/greeter

      greeter 是使用命令行部署的最简单的智能合约。

      contract mortal {
          /* Define variable owner of the type address*/
          address owner;
      
          /* this function is executed at initialization and sets the owner of the contract */
          function mortal() { owner = msg.sender; }
      
          /* Function to recover the funds on the contract */
          function kill() { if (msg.sender == owner) selfdestruct(owner); }
      }
      
      contract greeter is mortal {
          /* define variable greeting of the type string */
          string greeting;
      
          /* this runs when the contract is executed */
          function greeter(string _greeting) public {
              greeting = _greeting;
          }
      
          /* main function */
          function greet() constant returns (string) {
              return greeting;
          }
      }
      
    3. 如果您对客户端、合同源代码或在区块链上部署它们有特定问题,请返回此处。

    希望能帮助你自立:)

    【讨论】:

    • 感谢您的回答!!!!在区块链中插入合约需要多少成本?
    • 这个合约估计需要 17.2 万个 gas 来部署。 Gas preis 为 20 Gwei。 20 Gwei * 172000 Gas = 0.00344 Ether,在撰写本文时约为 0.0379 美元。
    • 每次更新或添加数据到合约时必须要付费吗?
    • 你不能更新合约,它们是不可变的。但是,您可以在真实合同之前有一个代理合同,它只是调用您在代理联系人中定义为变量的合同地址。
    • @baloo,为你解答!你知道我在创建合约之前下载了以太坊命令行后是否需要创建一个帐户吗?连接到私有测试网和公共网络有什么区别?
    【解决方案2】:

    你也可以使用(py)ethereumserpent - 为了保持蟒蛇精神- 如果你没问题,你可以看看“A Programmer’s Guide to Ethereum and Serpent”。 问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-28
      • 2021-06-29
      • 2019-12-09
      • 2018-06-23
      • 2022-07-17
      • 1970-01-01
      • 2017-08-07
      • 2018-07-02
      相关资源
      最近更新 更多