编写和测试智能合约

xiaoxiao2022-06-11  36

1. 智能合约是运行在以太坊上的程序。

使用Solidity语言开发智能合约程序,还在测试,没发布1.0版本。

 

2. 智能合约的编写 和 类 相似。智能合约代码如下:

// 用来计算无符号证书的加减法 pragma solidity ^0.4.1; contract Calc { address public owner; function add(uint x, uint y) returns(uint) { return x+y; } function sub(uint x, uint y) returns(uint) { return x - y; } }

3. 编译过程如下:

需要进入到    remix.ethereum.org  网址,把自己写的智能合约粘贴到左侧  test.sol。然后点右侧“Compile”,选择一个合适的solidity版本进行编译(本文选的是0.4.1)。

如果编译成功,就可以点击“Run”,选择“Deploy”。

这样就可以在“add” 里输入  “20, 30”,然后点击“add”。此时在浏览器正下方的黑框里弹出灰色提示

 

点击下拉箭头,就能看到我们想要的结果啦,如下图所示:

转载请注明原文地址: https://www.6miu.com/read-4931252.html

最新回复(0)