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
- SSR
- Redux
- REACT
- nextJS
- tailwindcss
- express.js
- CSS
- middleware
- Ethereum
- useState
- concept
- Props
- Interface
- bitcoin
- blockchain
- solidity
- JavaScript
- hardhat
- 기준
- web
- CLASS
- error
- graphQL
- typeScript
- 삶
- HTML
- evm
- built in object
- API
- node.js
Archives
- Today
- Total
ReasonJun
Solidity : array example 본문
728x90
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0 < 0.9.0;
contract Array {
uint[] public arr;
uint[] public arr2 = [1, 2, 3];
uint[10] public myFixedSizeArr; // 0
function get(uint i) public view returns (uint) {
return arr[i];
}
function get() public view returns (uint[] memory) {
return arr;
}
function push(uint i) public {
arr.push(i);
}
function pop() public {
arr.pop();
}
function getLength() public view returns (uint) {
return arr.length;
}
function remove(uint index) public {
// The length of the array does not change.
// Reset the index value to the default value.
// 0
delete arr[index];
}
function examples() external pure {
uint[] memory a = new uint[](5); // size is 5
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
// struct Todo {
// string text;
// bool completed;
// }
import "./1.sol";
contract Todos {
Todo[] public todos;
function create(string calldata _text) public {
todos.push(Todo(_text, false));
// todos.push(Todo({text:_text, completed: false}));
// Todo memory todo;
// todo.text = _text;
// todos.push(todo);
}
function get(uint _index) public view returns (string memory text, bool completed) {
Todo storage todo = todos[_index];
return (todo.text, todo.completed);
}
function updateText(uint _index, string calldata _text) public {
Todo storage todo = todos[_index];
todo.text = _text;
}
function toggleCompleted(uint _index) public {
Todo storage todo = todos[_index];
todo.completed = !todo.completed;
}
}
728x90
'Blockchain > Solidity' 카테고리의 다른 글
Solidity : constructor (0) | 2023.10.16 |
---|---|
Solidity : Event (0) | 2023.10.16 |
Solidity : Difference between memory and calldata (0) | 2023.10.16 |
Solidity : mapping (0) | 2023.10.16 |
Solidity : keccak256 (0) | 2023.10.16 |
Comments