# solidity 学习笔记 **Published by:** [homjewang](https://paragraph.com/@homjewang/) **Published on:** 2022-05-07 **URL:** https://paragraph.com/@homjewang/solidity ## Content // SPDX-License-Identifier: MIT pragma solidity^0.8.4; 以上版本可用 contract helloweb3{ 定义合约 helloweb3 string public _string="hello web3!"; } 定义公开的变量_string为 hello web3! 语句执行后会显示 hello web3! contract inttest{ uint256 public _number=20220330; 定义正整数变量_number为2022030 uint256 public _number1=_number+1; 定义正整数变量_number1的值为_numbei的值加1 uint256 public _number2=2**2; “**”代表指数 即 2**2=4,2**3=8... uint256 public _number3=7%2; "%"代表取余 7=2*3+1,即7%2=1 bool public _number4=_number2>_number3; bool 即为布尔型变量,有ture 和 felse两个状态 } 备注: int 定义整数型变量包含正整数(uint)和负整数 contract functiontest{ function add(int x,int y) external pure returns (int){ return x + y ; } 定义了一个计算和的函数 输入x,y返回x+y function sub(uint a,uint b) external pure returns(uint){ return a-b; } 定义了一个计算差的函数,输入a,b 返回 a-b } function (<parameter types>) {internal|external} [pure|view|payable] [returns (<return types>)] 其中 add和sub表示函数名称int x,int y表示函数的变量(int)和名称(xy) external表示 只能从合约外部访问,此外还有 internal 只能从合约内部访问 下面还有 pure view 关键字的区别 来自@0xAA via @0xAAvia @0xAA今天主要了解了合约的变量和函数 2022年5月8日01:41:02 ## Publication Information - [homjewang](https://paragraph.com/@homjewang/): Publication homepage - [All Posts](https://paragraph.com/@homjewang/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@homjewang): Subscribe to updates - [Twitter](https://twitter.com/snowstopsinger): Follow on Twitter