Programming

(truffle 환경 설정)Truffle compiler 오류 대처 - Error: Failed to fetch the Solidity comp

IT오이시이 2023. 8. 3. 17:38
728x90

(truffle 환경 설정) Truffle c9mpiler 오류 대처
- Error: Failed to fetch the Solidity compiler from the following locations

 
Truffle 을 사용하는 환경이 인터넷 사용이 안되거나  HTTPS와 같은 프로토콜이 차단된 환경에서 발생하는 문제입니다.
특히  금융 환경처럼 망분리가 되어 있는 환경은 https를  강제로  http로 변환해서 통신하는 데이터를 감시하고 있습니다. 그래서 https로 작동되는 외부 소스다운로드의 경우 오류가 발생  합니다. 이러한 경우 인터넷에 검색해도 나오지 않는 오류 해결 방법이 있어서 공유 합니다.  (
한참 이리저리  찾아 헤메다가  ㅠㅠ)
 
Truffle 설치 와 스마트 계약(Smart Contract) 개발

1. Truffle 설치 - 스마트 계약 개발 환경 구성 (truffle, ganache-cli, solc )
    - npm install -g truffle
    - npm install -g ganache-cli
    - npm install -g solc

2. Truffle 사용 - 스마트 계약(Smart Contract)개발
   - truffle create contract YourContractName
   - truffle create test YourTestName 

3. [Truffle 환경 설정] 컴파일 오류 대처 - Error: Failed to fetch the Solidity compiler from the following locations:
     - Are you connected to the internet?

4.  [Truffle 환경 설정] Deploy 오류 대처 - Error: Could not find artifacts for SimpleStorage from any sources
  - throw new Error("Could not find artifacts for " + import_path + " from any sources");


 ㅁ Truffle 명령을 이용한 스마트 계약 개발


# Truffle을 이용하여 스마트 컨트렉트를 이용하는 명령은 다음과 같습니다.
$ ganache-cli  -h 0.0.0.0 -p 8545 &  # 테스트용 블록체인 네트웍을 작동 합니다.

$ truffle init
->  smart contract  소스를 작성 합니다.
$ truffle compile
$ truffle migration ./migration/deploy_someContract.js
$ truffle deploy
$ truffle test ./test/someContrace_test.js

이번에는 truffle compile 에 대한 실행시 발생하는 오류에 대하여 알아 보고자 합니다.




 

1. Truffle compile 과정에서 오류가 발생  

Error: Failed to fetch the Solidity compiler from the following locations ~~~ ~~~ Are you connected to the internet?
Truffle을 예제를 따라서 컴파일을 하는데  이 컴파일 오류가 발생 합니다.

인터넷을 찾아보면 solc 컴파일러를 설치하라고 하지만 컴파일러는 설치를 했기에 문제가 없습니다.

[ipman@vm1 truffle2]$ truffle compile contracts/SimpleStorage.sol

Compiling your contracts...
===========================
? Fetching solc version list from solc-bin. Attempt #1
? Fetching solc version list from solc-bin. Attempt #2
? Fetching solc version list from solc-bin. Attempt #3
? Fetching solc version list from solc-bin. Attempt #4
? Fetching solc version list from solc-bin. Attempt #5
? Fetching solc version list from solc-bin. Attempt #6
Error: Failed to fetch the Solidity compiler from the following locations: https://relay.trufflesuite.com/solc/emscripten-wasm32/,https://binaries.soliditylang.org/emscripten-wasm32/,https://relay.trufflesuite.com/solc/emscripten-asmjs/,https://binaries.soliditylang.org/emscripten-asmjs/,https://solc-bin.ethereum.org/bin/,https://ethereum.github.io/solc-bin/bin/. Are you connected to the internet?


    at VersionRange.<anonymous> (/app_svc/.nvm/versions/node/v18.17.0/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:200:1)
    at Generator.next (<anonymous>)

 
컴파일러는 설치가 되어서 정상 작동하는 데 왜 오류가 나는지는 인터넷을 찾아도 답을 찾을수 없었습니다.

# 컴파일러는 정상 작동합니다.
# 아래 와 같이 컴파일 결과 파일들이 만들수 있습니다.
[ipman@vm1 contracts]$ solcjs --bin --abi SimpleStorage.sol
-rw-r--r--. 1 ipman ipman 268  8월  1 07:36 SimpleStorage.sol
-rw-r--r--. 1 ipman ipman 292  8월  3 17:35 SimpleStorage_sol_SimpleStorage.abi
-rw-r--r--. 1 ipman ipman 704  8월  3 17:35 SimpleStorage_sol_SimpleStorage.bin

 
 

2. 오류 원인 과 해결 방법 : 

Error: Failed to fetch the Solidity compiler from the following locations: ~~~ Are you connected to the internet?

version: "^0.8.0" 은 0.8.x  이상의 컴파일러를 이용하도록 하지만 로컬에서 solcjs가 인터넷과 연결되지 않아 설치가 되지 않아 버전 확인이 안되는 경우로 파악 됩니다.   

이런 경우에 로컬에 설치된 solc 버전 으로 설정을 수정하면 됩니다.  현재 로컬에는 0.8.4와 0.8.21  버전이 설치되어 있어서 
 
version: "^0.8.0" 을   version: "0.8.21",  또는   version:"0.8.4"  로 수정하면 컴파일이 됨을 확인 했습니다.
 

1) Solidity compiler 설치와 버전 확인

npm install solc 를 이용하여 solcjs를 설치 합니다.

[ipman@vm1 mySmartContract]$ npm install solc -g

changed 9 packages in 526ms


[ipman@vm1 mySmartContract]$ npm list solc -g
/app_svc/.nvm/versions/node/v18.17.0/lib
--- solc@0.8.21
 --- truffle@5.11.1
  --- @truffle/debugger@12.1.1
    --- @ensdomains/ensjs@2.1.0
      --- @ensdomains/ens@0.4.5
        --- solc@0.4.26

 
설치된 solc 버전을 확인하니 0.8.21 입니다.

[ipman@vm1 truffle2]$ solcjs --version
0.8.21+commit.d9974bed.Emscripten.clang



2) truffle-config.js에 컴파일러 버전명을 명시적으로 수정하여 해결 

다음과 같이 solcjs 의 버전에 맞추어  truffle-config.js 의 컴파일러 버전을 수정합니다.

version: "^0.8.0" 은 0.8.x  이상의 컴파일러를 이용하도록 하지만 로컬에서 solcjs가 인터넷과 연결되지 않아 설치가 되지 않아 버전 확인이 안되는 경우로 파악 됩니다. 

이런 경우에   version: "^0.8.0" 을   version: "0.8.21",  또는   version:"0.8.4"  로 수정하면 작동이 됩니다.

module.exports = {
// contracts_directory tells Truffle where the contracts you want to compile are located
contracts_directory: './contracts/local-dev',

// contracts_build_directory tells Truffle where to store compiled contracts
contracts_build_directory: './build/local-contracts',

  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    //
     development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
     },
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.21",      // Fetch exact version from solc-bin (default: truffle's version)
    }
  },

};

 
ㅁ 다시 컴파일러를 수정하고  truffle compile을 실행하면 정상 작동 됩니다.

[ipman@vm1 truffle2]$ truffle compile contracts/SimpleStorage.sol

Compiling your contracts...
===========================
> Compiling ./contracts/SimpleStorage.sol
> Artifacts written to /app_svc/truffle2/build/local-contracts
> Compiled successfully using:
   - solc: 0.8.21+commit.d9974bed.Emscripten.clang

 
 
* https://solc-bin.ethereum.org/bin/,https://ethereum.github.io/solc-bin/bin/. Are you connected to the internet? 에 대한 오류 해결이 되었나요 ... 혹시 안되면 댓글 달아 주시면 답변 드리겠습니다.

감사합니다.
 

[참조]
https://trufflesuite.com/docs/truffle/reference/configuration/

728x90
반응형