Learning-Solidity-From-Chainshot – 从链球中学习稳固性区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Learning-Solidity-From-Chainshot – 从链球中学习稳固性区块链毕设代写 是一篇很好的国外资料

Learning-Solidity-From-Chainshot

General Structure:-

In OnOffSwitch.sol, we are declaring isOn as a member variable of the OnOffSwitch contract. In Solidity these variables are generally referred to as state variables.

Just like in JavaScript classes, the constructor is run only once. For contracts, the constructor is run when it is deployed. The isOn state variable will be set to true on the deployment of this contract.

The isOn variable is accessible anywhere in this contract by name. Unlike JavaScript class variables, there is no need to use this. inside of the contract itself to gain access to the state variables.

The this keyword is still used in Solidity as a reference to the contract account.

Since state variables are referred to by name, constructor arguments using underscores to disambiguate is oftenly used.

It’s important to recognize that when we make a change to a state variable on a deployed smart contract, we are modifying permanent storage on the blockchain.

Local variables defined inside of a code block {} or passed in as arguments live in memory only for the length of their particular scope.

Control Structures:-

Solidity also has the return statement for passing back values from a function. One difference in Solidity is that multiple values can be returned from a Solidity function as a tuple:

</>function getValues() public pure returns (int, bool) { return (49, true); }</>

The following statement is perfectly valid in Solidity. Similarly, tuples can be used to destructure assignments similar to destructuring in JavaScript.

A tuple simply as a group of values in parenthesis. They are not a formal structure in Solidity so they are primarily used for returning and destructuring as shown above.

Along with the return keyword, Solidity also has if, else, while, do, for, break, and continue with the same semantics as JavaScript.

Visibility:-

public, private, internal, external keywords are called visibility specifiers because they determine from where functions can be accessed.

As you might expect, a public function is one that can be accessed from anywhere. A private function is one that cannot be. When a variable is declared public, a getter function is generated that will allow access to the variable state.

Static Typing:-

Solidity is a statically typed language, all variable must declare their type. By default, boolean values are false.

what if we tried storing a number in a bool? bool num = 10; //think..think..?

=> Ok So you will see Solidity won’t even compile with a statement like this. The compiler will raise a “TypeError: Type int_const 10 is not implicitly convertible to expected type bool.”

an exception raised at compile time is called a compile-time exception:-

This means that the compiler was unable to generate bytecode from the program, so we would not even be able to deploy this contract!

this is opposed to a run-time exception:-

Which would happen when someone tried to interact with a contract on the blockchain in some expected way. The exception would occur when a miner tries to validate the transaction. Unless the exception is caught, the transaction will fail and the miner will consume all the gas.


从Chainshot学习稳固性

一般结构:-

在OnOffSwitch.sol中,我们将isOn声明为OnOffSwitch契约的成员变量。这些变量通常称为状态变量

就像在JavaScript类中一样,构造函数只运行一次。对于契约,构造函数在部署时运行。在部署此协定时,isOn state变量将设置为true

可以通过名称访问此合同中的任何地方的isOn变量。与JavaScript类变量不同,不需要使用它。在契约本身内部获取对状态变量的访问

this关键字仍在Solidity中用作对合同帐户的引用

由于状态变量是按名称引用的,因此经常使用使用下划线消除歧义的构造函数参数

必须认识到,当我们更改已部署智能合约上的状态变量时,我们正在修改区块链blockchain上的永久存储

在代码块{}内定义或作为参数传入的局部变量仅在其特定作用域的长度内存在于内存中

控制结构:-

Solidity还有一个return语句,用于从函数传回值。Solidity的一个区别是,可以从Solidity函数返回多个值作为元组:

&lt/&燃气轮机;函数getValues()public pure returns(int,bool){return(49,true);}&lt/&燃气轮机

下面的陈述完全正确。类似地,元组可以用来分解分配,类似于JavaScript中的分解

一个元组,简单地表示为括号中的一组值。它们不是一个固定的正式结构,所以它们主要用于返回和分解,如上图所示

除了return关键字外,Solidity还有if、else、while、do、for、break和continue,其语义与JavaScript相同

可见性:-

public、private、internal和external关键字被称为可见性说明符,因为它们决定从何处可以访问函数

正如您所料,公共函数是可以从任何地方访问的函数。私有函数是一个不能被定义的函数。当变量声明为public时,将生成一个getter函数,该函数将允许访问变量状态

静态类型:-

Solidity是一种静态类型语言,所有变量都必须声明其类型。默认情况下,布尔值为false

如果我们尝试在布尔存储一个数字怎么办?布尔数=10//想..想

=&gt;你会看到Solidity甚至不能用这样的语句编译。编译器将引发一个“TypeError:Type int u const 10 is not implicit convertible to expected Type bool.”这意味着编译器无法从程序生成字节码,因此我们甚至无法部署此契约

编译时引发的异常称为编译时异常:-

当有人试图以某种预期的方式与区块链blockchain上的合同进行交互时,就会发生这种情况。当矿工尝试验证事务时,会发生异常。除非捕获到异常,否则事务将失败,矿工将消耗所有的天然气

这与运行时异常相反:-

Which would happen when someone tried to interact with a contract on the blockchain in some expected way. The exception would occur when a miner tries to validate the transaction. Unless the exception is caught, the transaction will fail and the miner will consume all the gas.

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/23188.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Learning-Solidity-From-Chainshot – 从链球中学习稳固性区块链毕设代写

提供最优质的资源集合

立即查看 了解详情