Blockchain/Solidity 8

Send Ether to the Smart Contract (2) 및 block.timestamp 개념 - 공부하는 도비

저번 피드에서 스마트 계약으로 이더를 보내는 방법을 알아보았습니다. 2023.01.04 - [Blockchain/Solidity] - Send Ether to the Smart Contract (1) 및 payable 개념 - 공부하는 도비 Send Ether to the Smart Contract (1) 및 payable 개념 - 공부하는 도비 Solidity에서 ether를 전송하는 스마트 컨트랙트를 작성하기 위해선, payable의 개념이 필수적입니다. "payable means that you can transfer ether with the transaction." payable엔 두 가지 종류가 있습니다. 1. address payab yang-wistory1009.tistory.com 오늘은..

Blockchain/Solidity 2023.02.01

Solidity 생성자(constructor) - 공부하는 도비

Smart Contract은 자바의 클래스나 인터페이스(객체)와 비슷합니다. 그래서 생성자라는 개념이 있고, 오늘은 Solidity의 생성자에 대해 알아보겠습니다. * What is a Constructor in Solidity 생성자는 타 언어처럼, 상태 변수를 바꾸거나 초기화할 때 사용이 됩니다. 또한, 생성자를 필수적으로 쓰진 않아도 됩니다. 생성자는 constructor이라는 키워드를 사용하여 만듭니다. // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; contract Exconstructor { constructor([optional-parameters]) access-modifier { } } - optional-parameters : 생성자에..

Blockchain/Solidity 2023.02.01

Send Ether to the Smart Contract (1) 및 payable 개념 - 공부하는 도비

Solidity에서 ether를 전송하는 스마트 컨트랙트를 작성하기 위해선, payable의 개념이 필수적입니다. "payable means that you can transfer ether with the transaction." payable엔 두 가지 종류가 있습니다. 1. address payable 2. function payable address 타입과 함께 사용되면 지불가능한 주소(address payable)의 타입이 되고, function과 함께 사용되면 지불가능한 함수 (function _ () payable)이 됩니다. Members of Address Payable Types : address payable 타입의 멤버엔 .transfer과 .send가 있습니다. - .transfe..

Blockchain/Solidity 2023.01.04

delete element of array and mapping - 공부하는 도비

array의 인덱스 번호로 element 삭제 방법 pragma solidity ^0.8.1; contract Practice { uint256[] private arr; function remove(uint256 _index) private { require(_index < arr.length, "index out of bound"); for (uint i = _index; i < arr.length - 1; i++) { arr[i] = arr[i + 1]; } arr.pop(); } function test() external { // case_1 arr = [1, 2, 3, 4, 5]; remove(2); // want : arr = [1, 2, 4, 5] // checking assert(arr[..

Blockchain/Solidity 2023.01.02

require() 사용 - 공부하는 도비

Solidity는 에러를 제어하기 위해 다양한 함수를 제공하고, 일반적으로 에러가 발생하면 원래의 상태로 돌아갑니다. 에러를 컨트롤하기 위해서, 다음과 같은 메소드들이 있습니다. ● require(bool condition) ● require(bool condition, string memory message) ● assert(bool condition) ● revert() ● revert(string memory reason) 오늘은 위 메소드들 중 require를 자세하게 살펴보겠습니다. 1. require(bool condition) - In case condition is not met, this method call reverts to original state. This method is to..

Blockchain/Solidity 2023.01.02

msg.sender 사용 - 공부하는 도비

2022.12.29 - [블록체인] - [블록체인] (Solidity).balance(uint256) 사용 - 공부하는 도비 [블록체인] (Solidity) .balance(uint256) 사용 - 공부하는 도비 오늘은 특정 주소를 셋팅한 후, 그 주소의 잔고를 출력 또는 리턴 받아보겠습니다. Remix - Ethereum IDE Solidity 0.8.1 (버전이 높을 수록 다 좋은 것은 아닙니다. 0.8.1버전은 아마 글 쓰는 시점 가장 최신 yang-wistory1009.tistory.com 저번 피드에서 특정 주소의 잔고를 리턴/출력하는 방법을 알아보았습니다. 오늘은 constructor() 생성자를 사용하여 계약 배포자의 주소를 설정하고, 그 주소의 잔고를 리턴 받아보겠습니다. Remix - E..

Blockchain/Solidity 2023.01.02

<address>.balance(uint256) 사용 - 공부하는 도비

오늘은 특정 주소를 셋팅한 후, 그 주소의 잔고를 출력 또는 리턴 받아보겠습니다. Remix - Ethereum IDE Solidity 0.8.1 (버전이 높을 수록 다 좋은 것은 아닙니다. 0.8.1버전은 아마 글 쓰는 시점 가장 최신버전이나 각자가 생각하는 가장 stable한 버전을 쓰시면 됩니다.) .balance (uint256)은 Wei 형태로 주소의 balance를 리턴합니다. 1ether는 10^18 wei와 동일합니다. 1. 코드에 특정 주소를 적어두고, 그 주소의 balance를 return 받기 pragma solidity ^0.8.1; contract test { address public myAddress = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC..

Blockchain/Solidity 2022.12.29

Ethereum Goerli Test Network로 테스트 이더 받기 - 공부하는 도비

블록체인을 공부하면서 느끼는 건 지금 현재도 여러 새로운 기술이 나오고 변경되고 있다는 것이고, 예전에 잘 써왔던 사이트들이 안된다거나 사용할 수 없는 경우가 많다는 것이다. 저는 Ethereum Goerli Test Network로 테스트 이더를 받아서 썼던 거 같은데, 오늘 보니 공식 사이트 이용이 안돼서 새로운 사이트를 알려드리려고 합니다. 우선, Buy를 눌러주고 Get Ether도 눌러줍니다. 그럼 다음과 같은 사이트가 나오는데, 이 사이트에서 더 이상 이더를 얻을 순 없습니다. 아래 링크로 이동해줍니다. https://goerlifaucet.com/ 간단히 로그인을 해줍니다. 메타마스크의 사용자 주소를 붙여 넣고 Send Me ETH를 클릭해 줍니다. 네트워크 상황에 따라 다르겠지만, 잠시만 ..

Blockchain/Solidity 2022.12.20