Solidity开发实践(一)发布第一个智能合约

首先进入Solidity常用的IDE是在线编译环境remix.ethereum.org。

进入后点击文件树上的新建按钮,输入文件名和后缀新建文件。

代码本身没有难度,主要是适应下语言,环境和IDE。

pragma solidity >=0.7.0 < 0.9.0;

/* 

You just land your new blockchain job to build smart contracts for an awesome DAO catching fire!

Immediately, your boss throws at your a scrip of code tons of bugs in it. She says, 

'Hey you! Fix this code and get this smart contract running and help save our DApp from crashing!'

The clock is ticking and this is the perfect opportunity to prove your skills and show what you are made of.

Your assignment is to fix the code below full of syntax errors and get this contract successfully deployed on 
the Ethereum network. 

Good luck! 

*/

 contract learnFunctions {
    
   
   function remoteControlOpen(bool closedDoor, bool openDoor ) public returns(bool) {}
  
    
      uint a = 45;
      
   function addfValues() public view returns (uint) {
       uint b = 3;
       uint result = a + b;
       return result;
   }
   
   
   function addNewValues() public view returns (uint) {
       uint b = 5;
       uint result = a + b;
       return result;
   
   
   }
   
   uint b = 4; 
      
    function multiplyCalculatorByFour(uint a, uint c) public view returns(uint) {
        uint result = a * c;
        return result;
     }
    
   function divideCalculatorByFour(uint a) public view returns (uint) {
        uint result = a/b;
        return result;
    }
   
 }

还挺离谱的这个代码款可选领域居然无Solidity语言的选项,果然国内因为这个管制原因,还是处于小众阶段。

OK这就是实现了一个常见的计算器功能了,那么他的实现和命令行出现窗口不一样是有一个类似自带前端页面的感觉,就是有写好的把Function写成按钮的形式,然后输入值也是有文本空间。

Solidity开发实践(一)发布第一个智能合约_第1张图片

 然后目前代码上还没有上难度,课程讲的比较细,这是一个让我们debug的demo。真的是常见的BUG都有,然后当前仍存在的问题。

1.既然IDE是一致的为什么显示字体颜色和课上的不一样。

2. 我的代码报了Warning,虽然说可以忽略,不影响运行,但是很好奇为什么用输入两个变量就会出现Infinite Gas 的情况。 Gas如何计算。

其实也看了大几十节短课了,进度还是太慢了。之后要抓抓紧。有新的收获或者解决了之前的困惑就再来更新。

终极目标是掌握Solidity,熟悉开发智能合约的流程。

你可能感兴趣的:(区块链,智能合约)