SmartContract 테스트넷 배포 (3)
1 ECAE_SmartContract 실행
- 지난번 계시물에서 컴파일 했던 것은 test 예제
- 이번 게시물에서는 실제 ECAC_SmartContract를 배포하고자 함
(1) 폴더 생성 및 truffle init

(2) npm init -y
* yes 옵션 안달면 하나하나 일일이 설정해줘야 함 그냥 yes하고 나중에 수정하는게 편함

(3) npm install -E openzeppelin-solidity

(4) ATOM 에디터에서 새로운 폴더구조가 형성된 것 확인
* 예제와 달리 Migration.sol, intial_migration 생성 안됨

(5) npx truffle version 명령어로 솔리디티 버전 확인

(6) truffle-config.js 의 compilers 버전 수정

(7) ECAC_Smartcontract.sol과 migration 파일 생성

(8) ECAC_Smartcontract.sol에는 기존에 작성한 SmartContract를 가져왔고, migrarion은 아래와 같이 수정

(9) npx truffle compile
* 생성자 함수인 constructor 부분에서 오류가 나기에 주석처리 함
* 리믹스 환경에서는 다른 생성자 형식이 오류가 났으나 버전의 문제라고 했기에 버전이 바뀌어 발생하는 문제라 추측

(10) npx truffle migrate


성공 !
2 MEW
(1) ECAC_Smartcontract > build > contracts > json > ABI[] 전체 복사

(2) MEW의 interact with Contract에서 스마트컨트랙트의 주소와 복사한 ABI 각각 입력 후 interact

(3) Interact with contract 창으로 넘어가며 내가 작성한 함수들을 확인 및 실행할 수 있음
* public으로 설정한 함수들만 표시

(4) AddPoint_linkes 함수 테스트


3 openzeppelin-solidity 사용
(1) ECAC_Smartcontract.sol 코드에 ERC20.sol을 임포트
import '../node_modules/openzeppelin-solidity/contracts/token/ERC20';

* ERC20.sol에 -mint를 생성했을 때 초기화해주는 코드가 들어있음

(2) 터미널에서 다시 npx truffle compile, npx truffle migrate 실행

(3) MEW에서 다시 address와 ABI 갱신

(4) Public으로 선언하지 않은 함수들도 보임
* ECAC_Smartcontract는 모든 함수가 공개형이므로 차이 없음

4 Testnet 배포
(1) infura.io 접속 후 로그인
Ethereum API | IPFS API & Gateway | ETH Nodes as a Service
Infura's development suite provides instant, scalable API access to the Ethereum and IPFS networks. Connect your app to Ethereum and IPFS now, for free!
infura.io
(2)ECAC_Smartcontract Key 생성 > 필요한 키는 엔트포인트가 Ropsten네트워크인 Key이나 옵션에 없음 > ???
* 일단은 Prater Test Network를 사용해서 실습 진행
* ENDPoints 및 줄에 있는 URL 복사


(3) truffle-config.js 파일 수정


(4) npm i @truffle/hdwallet-provider

(5)ECAC_Smartcontract 폴더에 .secret 파일 생성하고 Metamask 비밀번호 복구 문구 입력

(6) truffle compile / truffle migrate --network prater // 오류 ! 4-2부터 다시

5 Etherscan
(1) Etherscan 접속
TESTNET Ropsten (ETH) Blockchain Explorer
Etherscan allows you to explore and search the Ropsten blockchain for transactions, addresses, tokens, prices and other activities taking place on Ropsten (ETH)
ropsten.etherscan.io
(2) truffle migrate --network prater으로 나온 contract address를 입력하여 Smartcontract 확인

(3) 결과
* Ropsten Network 사용해야 하는 것 같음 이 부분만 다시 해볼것 !
* 참고자료
https://jeongjun9-diary.tistory.com/26
https://velog.io/@nara7875/BlockChain-cobzoqbi
https://kimsfamily.kr/330?category=903691
https://docs.openzeppelin.com/contracts/3.x/erc20
https://github.com/ConsenSys/ethereum-developer-tools-list/blob/master/README_Korean.md