///
Search
♥️

13.Klaytn BApp 만들기 (오류도 해결)

이전자료

일단 맨 처음 npm 을 설치한다.
명령어
npm install
JavaScript
복사
오래걸림
여기서 오류가 엄청 나올수 있다. 여기에서 오류가 발생할 경우 아래의 글을 참고하고 yklovejesus@gmail.com에 질문해라

오류

맨 처음 오류 발생
PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter> npm install npm WARN deprecated safe-event-emitter@1.0.1: Renamed to @metamask/safe-event-emitter > scrypt@6.0.3 preinstall C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt > node node-scrypt-preinstall.js > scrypt@6.0.3 install C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt > node-gyp rebuild C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild ) gyp ERR! find Python gyp ERR! find Python Python is not set from command line or npm configuration gyp ERR! find Python Python is not set from environment variable PYTHON gyp ERR! find Python checking if "python" can be used gyp ERR! find Python - "python" is not in PATH or produced an error gyp ERR! find Python checking if "python2" can be used gyp ERR! find Python - "python2" is not in PATH or produced an error gyp ERR! find Python checking if "python3" can be used gyp ERR! find Python - "python3" is not in PATH or produced an error gyp ERR! find Python checking if the py launcher can be used to find Python 2 gyp ERR! find Python - "py.exe" is not in PATH or produced an error gyp ERR! find Python checking if Python is C:\Python27\python.exe gyp ERR! find Python - "C:\Python27\python.exe" could not be run gyp ERR! find Python checking if Python is C:\Python37\python.exe gyp ERR! find Python - "C:\Python37\python.exe" could not be run gyp ERR! find Python gyp ERR! find Python ********************************************************** gyp ERR! find Python You need to install the latest version of Python. gyp ERR! find Python Node-gyp should be able to find and use Python. If not, gyp ERR! find Python you can try one of the following options: gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe" gyp ERR! find Python (accepted by both node-gyp and npm) gyp ERR! find Python - Set the environment variable PYTHON gyp ERR! find Python - Set the npm configuration variable python: gyp ERR! find Python npm config set python "C:\Path\To\python.exe" gyp ERR! find Python For more information consult the documentation at: gyp ERR! find Python https://github.com/nodejs/node-gyp#installation gyp ERR! find Python ********************************************************** gyp ERR! find Python gyp ERR! configure error gyp ERR! stack Error: Could not find any Python installation to use gyp ERR! stack at PythonFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:307:47) gyp ERR! stack at PythonFinder.runChecks (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:136:21) gyp ERR! stack at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:225:16) gyp ERR! stack at PythonFinder.execFileCallback (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:271:16) gyp ERR! stack at exithandler (child_process.js:315:5) gyp ERR! stack at ChildProcess.errorhandler (child_process.js:327:5) gyp ERR! stack at ChildProcess.emit (events.js:315:20) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) gyp ERR! stack at onErrorNT (internal/child_process.js:465:16) gyp ERR! stack at processTicksAndRejections (internal/process/task_queues.js:80:21) gyp ERR! System Windows_NT 10.0.19042 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt gyp ERR! node -v v14.16.0 gyp ERR! node-gyp -v v5.1.0 gyp ERR! not ok npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself. npm WARN requestretry@2.0.2 requires a peer of request@~2.87.0 but none is installed. You must install peer dependencies yourself. npm WARN klay-dapp-boilerplate@0.0.1 No repository field. npm WARN klay-dapp-boilerplate@0.0.1 No license field. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! scrypt@6.0.3 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the scrypt@6.0.3 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\glory\AppData\Roaming\npm-cache\_logs\2021-03-08T12_30_51_586Z-debug.log PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter>
JavaScript
복사
시도 1 효과 없음
PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter> npm install --global --production windows-build-tools npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated har-validator@5.1.5: this library is no longer supported > windows-build-tools@5.2.2 postinstall C:\Users\glory\AppData\Roaming\npm\node_modules\windows-build-tools > node ./dist/index.js Downloading python-2.7.15.amd64.msi [============================================>] 100.0% of 20.25 MB (462.78 kB/s) Downloaded python-2.7.15.amd64.msi. Saved to C:\Users\glory\.windows-build-tools\python-2.7.15.amd64.msi. Downloading vs_BuildTools.exe [============================================>] 100.0% of 1.12 MB (639.91 kB/s) Downloaded vs_BuildTools.exe. Saved to C:\Users\glory\.windows-build-tools\vs_BuildTools.exe. Starting installation... Please restart this script from an administrative PowerShell! The build tools cannot be installed without administrative rights. To fix, right-click on PowerShell and run "as Administrator". npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! windows-build-tools@5.2.2 postinstall: `node ./dist/index.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the windows-build-tools@5.2.2 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\glory\AppData\Roaming\npm-cache\_logs\2021-03-08T12_30_12_262Z-debug.log
JavaScript
복사
시도 2 파이썬 설치
windows에서 이 에러가 발생하는 이유는 python2.7이 설치되지 않았거나, python2.7의 path가 npm에 등록되지 않았기 때문입니다. https://www.python.org/downloads/ 에서 python2.7 버전을 설치한 후, npm config set python C:\python27\python.exe (컴퓨터에 파이썬이 설치된 경로) 로 npm에 python을 등록시켜 주시면 됩니다. (참고) https://www.npmjs.com/package/node-gyp 출처: https://pragp.tistory.com/entry/npm-Error-gyp-failed-with-exit-code-1 [Pragmatic Programming]
JavaScript
복사
효과 없음
PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter> npm config set python C:\python27\python.exe >> PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter> PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter> npm install npm WARN deprecated safe-event-emitter@1.0.1: Renamed to @metamask/safe-event-emitter > scrypt@6.0.3 preinstall C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt > node node-scrypt-preinstall.js > scrypt@6.0.3 install C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt > node-gyp rebuild C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild ) gyp ERR! find VS gyp ERR! find VS msvs_version not set from command line or npm config gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp ERR! find VS checking VS2019 (16.8.31019.35) found at: gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" gyp ERR! find VS - "Visual Studio C++ core features" missing gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use gyp ERR! find VS looking for Visual Studio 2015 gyp ERR! find VS - not found gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS You need to install the latest version of Visual Studio gyp ERR! find VS including the "Desktop development with C++" workload. gyp ERR! find VS For more information consult the documentation at: gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows gyp ERR! find VS ************************************************************** gyp ERR! find VS gyp ERR! configure error gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (child_process.js:315:5) gyp ERR! stack at ChildProcess.emit (events.js:315:20) gyp ERR! stack at maybeClose (internal/child_process.js:1048:16) gyp ERR! System Windows_NT 10.0.19042 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt gyp ERR! node -v v14.16.0 gyp ERR! node-gyp -v v5.1.0 gyp ERR! not ok npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself. npm WARN requestretry@2.0.2 requires a peer of request@~2.87.0 but none is installed. You must install peer dependencies yourself. npm WARN klay-dapp-boilerplate@0.0.1 No repository field. npm WARN klay-dapp-boilerplate@0.0.1 No license field. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! scrypt@6.0.3 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the scrypt@6.0.3 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\glory\AppData\Roaming\npm-cache\_logs\2021-03-08T12_37_40_915Z-debug.log PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter>
JavaScript
복사
세번째 시도 npm install truffle-hdwallet-provider
쓸데 없음
PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter> npm install truffle-hdwallet-provider npm WARN deprecated truffle-hdwallet-provider@1.0.17: WARNING: This package has been renamed to @truffle/hdwallet-provider. npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that. > scrypt@6.0.3 preinstall C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt > node node-scrypt-preinstall.js > bufferutil@4.0.3 install C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\bufferutil > node-gyp-build > scrypt@6.0.3 install C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt > node-gyp rebuild C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild ) gyp ERR! find VS gyp ERR! find VS msvs_version not set from command line or npm config gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp ERR! find VS checking VS2019 (16.8.31019.35) found at: gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" gyp ERR! find VS - "Visual Studio C++ core features" missing gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use gyp ERR! find VS looking for Visual Studio 2015 gyp ERR! find VS - not found gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS You need to install the latest version of Visual Studio gyp ERR! find VS including the "Desktop development with C++" workload. gyp ERR! find VS For more information consult the documentation at: gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows gyp ERR! find VS ************************************************************** gyp ERR! find VS gyp ERR! configure error gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14) gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (child_process.js:315:5) gyp ERR! stack at ChildProcess.emit (events.js:315:20) gyp ERR! stack at maybeClose (internal/child_process.js:1048:16) gyp ERR! System Windows_NT 10.0.19042 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter\node_modules\scrypt gyp ERR! node -v v14.16.0 gyp ERR! node-gyp -v v5.1.0 gyp ERR! not ok npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself. npm WARN requestretry@2.0.2 requires a peer of request@~2.87.0 but none is installed. You must install peer dependencies yourself. npm WARN klay-dapp-boilerplate@0.0.1 No repository field. npm WARN klay-dapp-boilerplate@0.0.1 No license field. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! scrypt@6.0.3 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the scrypt@6.0.3 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\glory\AppData\Roaming\npm-cache\_logs\2021-03-08T12_41_01_299Z-debug.log PS C:\Users\glory\Desktop\(Github)\_Klaytn\addition-game-starter>
JavaScript
복사
뭔가 이상해서 검색해 보니 npm install --global windows-build-tools 쓸때에는 관리자 권한으로 열어서 써야한다고 한다.
python 버전은 수정은 되었지만 아직도 npm install이 안된다...
내가 알고보니 파일 버전이 틀렸었다. 5.3 BApp 으로 실습을 했어야 했는데 실수했다.
npm install 한번 했는데 또 안되어서 그냥 다시 한번 해봤는데 이제서야 됬다.
완료 화면
PS C:\Users\glory\Desktop\(Github)\_Klaytn\5.3> npm install npm WARN deprecated safe-event-emitter@1.0.1: Renamed to @metamask/safe-event-emitter npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself. npm WARN requestretry@2.0.2 requires a peer of request@~2.87.0 but none is installed. You must install peer dependencies yourself. npm WARN klay-dapp-boilerplate@0.0.1 No repository field. npm WARN klay-dapp-boilerplate@0.0.1 No license field. added 12 packages from 15 contributors, removed 1 package and updated 3 packages in 19.718s PS C:\Users\glory\Desktop\(Github)\_Klaytn\5.3>
JavaScript
복사
5.3.egg
87.7KB
migration 폴더 안에 새로운 파일을 넣는다.

/Migrations/2_deploy_contracts.js

const AdditionGame = artifacts.require('./AdditionGame.sol')//addition 컨트랙을 노드에 배포하는 것을 설치한다. const fs = require('fs') module.exports = function (deployer) { deployer.deploy(AdditionGame)//(_) 인자도 AdditionGame으로 바꾼다. 배포하는 과정에서 얻을수 있는 정보들을 비앱 내에 어떤 파일에다가 저장하는 코드를 작성할 예정이다. .then(() => {//나중에 컨트랙 인스턴스 만드는데 아주 유용하게 쓰일수 있다. 여기서 부터 deployer가 AdditionGame을 deploy 하고 나서 then을 통해 프라미스 json 데이터를 받는다. if (AdditionGame._json) {//에디션 게임에 제이슨 데이터를 받으면 파일 시스템 모듈을 통해 파일에다가 저장할 것이다. 그렇기 위해서 input을 시켜야한다. 그렇기 위해 맨위로 올라가면 const fs = require('fs') 을 작성을 해야한다.fs.writeFile( 'deployedABI', JSON.stringify(AdditionGame._json.abi), (err) => { if (err) throw err console.log("파일에 ABI 입력 성공"); }) } fs.writeFile( 'deployedAddress', AdditionGame.address, (err) => { if (err) throw err console.log("파일에 주소 입력 성공"); }) }) }
JavaScript
복사
여기 까지 되었으면 2개의 파일을 만들 것이다.
abi 와 컨트랙 주소를 저장할수 있는 곳이다.
이제 파일 시스템을 써서 각각의 파일에다가 저장을 한다. (위의 코드에서 주석만 추가할 예정입니다.)
module.exports = function (deployer) { deployer.deploy(AdditionGame)//(_) 인자도 AdditionGame으로 바꾼다. 배포하는 과정에서 얻을수 있는 정보들을 비앱 내에 어떤 파일에다가 저장하는 코드를 작성할 예정이다. .then(() => {//나중에 컨트랙 인스턴스 만드는데 아주 유용하게 쓰일수 있다. 여기서 부터 deployer가 AdditionGame을 deploy 하고 나서 then을 통해 프라미스 json 데이터를 받는다. if (AdditionGame._json) {//에디션 게임에 제이슨 데이터를 받으면 파일 시스템 모듈을 통해 파일에다가 저장할 것이다. 그렇기 위해서 input을 시켜야한다. 그렇기 위해 맨위로 올라가면 const fs = require('fs') 을 작성을 해야한다.fs.writeFile( 'deployedABI', //어떤 파일에 쓸것인지 정의 JSON.stringify(AdditionGame._json.abi), // json으로 받은 abi정보를 string으로 넘겨서 받는것이다. (err) => { //마지막으로 error 처리를 하는 방법이다. if (err) throw err// 에러가 발생하면 err를 던져라 console.log("파일에 ABI 입력 성공");// 없으면 콘솔에다가 로그를 찍는다. }) } fs.writeFile(//1.파일을 입력받는다. 2개의 인자를 받는다. /* 'deployedABI', JSON.stringify(AdditionGame._json.abi), */ 'deployedAddress',// 어디에 저장 할 것인지 AdditionGame.address, //이번에는 주소이다 abi가 아님 (err) => {//에러처리 위에랑 똑같이 if (err) throw err console.log("파일에 주소 입력 성공"); }) }) }
JavaScript
복사
ABI는 블록체인과 컨트랙간의 상호작용을 할 수 있는 내용이다.

마지막의 환경 설정

배포를 할때 어느 네트워크에 할 것 인지를 정의 한다.
5.4.zip
85.9KB
아래의 파일을 생성한다.

/truffle.js

const PrivateKeyConnector = require('connect-privkey-to-provider') //여기에서 정의를 한다. connect-privkey-to-provider 라이브러리를 가져오는 작업이다. const NETWORK_ID = '1001' // 네트워크 아이디라는 상수도 만든다. // 바오밥 고유의 네트워크를 의미한다. const GASLIMIT = '20000000' // 배포하는데 들어가는 가스 한도 const URL = `https://api.baobab.klaytn.net:8651` //const URL은 클레이튼의 플로드가 현재 돌아가고있는 주소를 대입하였다. const PRIVATE_KEY = '12312312312312312312312312321312312' //비밀키를 담는 상수가 필요하다. 우리가 가지고 있던 비밀키를 여기에 넣어야한다. module.exports = { //이제 이 설정들을 Model.exports 안에다가 저장해야한다. networks: { //네트워크는 클레이튼을 쓴다고 했고 4가지의 옵션을 말한다. klaytn: { provider: new PrivateKeyConnector(PRIVATE_KEY, URL),// 클레이튼 네트워크를 제공하는 공급자를 명시하는 것인데 PrivateKeyConnector를 생성하고 오른쪽에 두개의 인자를 넘깁니다. 첫번쨰는 비밀키를 넘기고 플로드가 돌아가는 네트워크 주소를 넘긴다. 내 비밀키를 사용해서 실습하는 것이다. gas: GASLIMIT,// 게스 데입 //network_id: NETWORK_ID, gasPrice: null, //가격을 자동으로 만든다. } }, }
JavaScript
복사
여기까지 스마트 계약을 배포할 수 있는 조건들을 마쳤다.
이제 배포를 시작한다.
cmd 창에 아래의 명령어를 입력한다.
truffle deploy --network klaytn
JavaScript
복사
오류 발생
PS C:\Users\glory\Desktop\(Github)\_Klaytn\5.4> truffle deploy --network klaytn truffle : 이 시스템에서 스크립트를 실행할 수 없으므로 C:\Users\glory\AppData\Roaming\npm\truffle.ps1 파일을 로드할 수 없습니다. 자세한 내용은 about_Execution_Policies(https://go.microsoft.com/fwlink/?LinkID=135170)를 참조하십시오. 위치 줄:1 문자:1 + truffle deploy --network klaytn + ~~~~~~~ + CategoryInfo : 보안 오류: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess PS C:\Users\glory\Desktop\(Github)\_Klaytn\5.4>
JavaScript
복사
관리자 권한으로 실행 후 테스트
Microsoft Windows [Version 10.0.19042.804] (c) 2020 Microsoft Corporation. All rights reserved. C:\Windows\system32>truffle version Truffle v4.1.15 (core: 4.1.15) Solidity v0.4.25 (solc-js) C:\Windows\system32>cd .. C:\Windows>cd .. C:\>cd Users C:\Users>cd glory C:\Users\glory>cd Desktop C:\Users\glory\Desktop>cd "(Github)" C:\Users\glory\Desktop\(Github)>cd _Klaytn C:\Users\glory\Desktop\(Github)\_Klaytn>cd 5.4 C:\Users\glory\Desktop\(Github)\_Klaytn\5.4>truffle deploy --network klaytn C:\Users\glory\Desktop\(Github)\_Klaytn\5.4>
JavaScript
복사
위의 예시는 성공 예시
ABI와 컨트랙 주소 파일 안에 내용이 새롭게 적혀있는 것을 확인할 수 있다.
마지막으로 배포를하게 된다면 빌드라는 폴더가 생성 되는데 그안에 컨트랙스 폴더가 있고 json 파일이 2개 있을 것이다. 이걸 영어로 아티팩트라고 한다.
각각의 파일은 해당 컨트랙에 ABI 정보와 모든 정보를 담고 있다.
abi는 어플리케이션 바이너리 인터페이스 약자이다. 이안에 보면 에디셔널게임에 쓰는 함수와 변수들이 json 형식으로 되어있다.
블록체인 컨트랙에 배포했을때에 호출하고 예상됬던 형식으로 리턴될수 있도록 보장하는 것이다.
컨트랙과 상호작용 할 수 있는 것을 정의하는 곳이다.
거의 맨아래 보면 네트워크 색션이 있는데 1001 이건 클레이튼 고유 네트워크 아이디라고 했고
주소를 보면 해당 컨트랙이 이주소로 배포되어있다는것을 확인 할수 있다.
재배포를 하고자 한다. 수정할려고 하면 노드에다가 제 배포 해야하잖아 그래서 이때 쓴다.
truffle deploy —compile-all —reset —network klaytn
truffle deploy --compile-all --reset --network klaytn
JavaScript
복사
실행 시키면 노드의 컨트랙을 재 배포 시킨다.
배포를 할 때 마다 주소가 바뀐다.