250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Ethereum
- blockchain
- nextJS
- typeScript
- CSS
- HTML
- Interface
- built in object
- hardhat
- express.js
- middleware
- bitcoin
- Redux
- useState
- JavaScript
- concept
- Props
- REACT
- error
- tailwindcss
- evm
- CLASS
- graphQL
- solidity
- 삶
- API
- 기준
- SSR
- web
- node.js
Archives
- Today
- Total
ReasonJun
Solidity : function / Parameter / wei / ether / gas 본문
Blockchain/Solidity
Solidity : function / Parameter / wei / ether / gas
ReasonJun 2023. 10. 16. 12:33728x90
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0 < 0.9.0;
contract Ex1 {
uint public a = 3;
uint public b = 5;
function myBlock() public returns (uint, uint){
a = 99;
b = 0;
return(a, b);
}
function myBlcok2(uint c) public {
a = c;
}
function myBlock3() public pure returns(uint age, uint weight) {
age = 20;
weight = 55;
}
function getValue(uint e) public pure returns (uint) {
return e;
}
function getReference(string memory f) public pure returns (string memory){
return f;
}
uint public g = 3; // 100
uint public h = myBlock4();
function myBlock4() public returns(uint) {
g = 100;
return g;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0 < 0.9.0;
contract Ex2 {
function myBlock(string memory str) public pure returns (uint, string memory, bytes memory) {
uint num = 99;
bytes memory byt = hex"01";
return(num, str, byt); // 99 , wef, 0x01
}
function myBlock2(string memory str) external pure returns (string memory) {
return str; // external => calldata or memory (Reference type only)
}
}
wei / ether
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0 < 0.9.0;
contract Ether_1 {
uint public oneWei = 1 wei;
uint public oneEther = 1 ether;
// 1 ehter = 1e18 wei
}
Gas
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0 < 0.9.0;
// Pay transaction costs with gas.
// Transaction requests with higher gas prices are processed first
// Refund unused gas
contract Gas_1 {
uint public i = 0;
// If all the sending gas is used, the transaction will fail
// state change canceled
// Used gas is not refunded
function forever() public {
// Run loop until all gas is used up
// and the transaction fails
while (true) {
i += 1;
}
}
}
// Gas limit: Maximum gas usage set by the user
// block gas limit: Maximum amount of gas allowed for a block - set by the network
728x90
'Blockchain > Solidity' 카테고리의 다른 글
Solidity : keccak256 (0) | 2023.10.16 |
---|---|
Solidity : event / emit (0) | 2023.10.16 |
Solidity : Modifier (pure, view) (0) | 2023.10.16 |
Solidity : Visibility (0) | 2023.10.15 |
Solidity : Operator / Shift operator (1) | 2023.10.15 |
Comments