Solidity
[Solitidy+Go] geth로 스마트 컨트랙트 배포하기 - 1. 초기 구성
piatoss
2023. 12. 13. 19:45
1. 사용한 기술
linux 환경 기반
- go 1.21 (스마트 컨트랙트 배포 및 상호작용)
- node v20.3.0 (OpenZeppelin 라이브러리 사용)
- solc 0.8.22+commit.4fc1097e (Solidity 파일 컴파일)
- abigen 1.13.4-stable (abi 파일을 사용해 go 코드 생성)
- anvil 0.2.0 (로컬 테스트넷 실행 - ganache cli나 다른 로컬 테스트넷도 가능)
- alchemy (RPC Endpoint 제공)
- polygonscan (mumbai 테스트넷에 배포된 스마트 컨트랙트 검증)
2. solc 및 geth 설치
solc 설치
Installing the Solidity Compiler — Solidity 0.8.24 documentation
Installing the Solidity Compiler Edit on GitHub Installing the Solidity Compiler Versioning Solidity versions follow Semantic Versioning. In addition, patch-level releases with major release 0 (i.e. 0.x.y) will not contain breaking changes. That means code
docs.soliditylang.org
geth 설치
Installing Geth | go-ethereum
Guide to installing Geth
geth.ethereum.org
abigen 빌드
$ cd $GOPATH/src/github.com/ethereum/go-ethereum
$ go build ./cmd/abigen
3. 프로젝트 초기화
Go 모듈 초기화 및 패키지 설치
$ go mod init <your-module-name>
$ go get github.com/joho/godotenv
github.com/joho/godotenv 패키지는 .env 파일을 불러오기 위해 필요
node 프로젝트 초기화 및 라이브러리 설치
$ npm init -y
$ npm i @openzeppelin/contracts
@openzeppelin/contracts는 ERC20 토큰 컨트랙트를 사용하기 위해 필요
최상위 디렉토리 구조
$ tree -L 1
.
├── README.md
├── build
├── cmd
├── contracts
├── gen
├── go.mod
├── go.sum
├── node_modules
├── package-lock.json
├── package.json
└── verify
4. 전체 코드
GitHub - piatoss3612/go-ethereum-practice
Contribute to piatoss3612/go-ethereum-practice development by creating an account on GitHub.
github.com