Blockchain
Truffle migrate Error You must specify a network id in your development configuration in order to use this network
개발자 염상진
2022. 9. 2. 11:07
Error Code
Truffle에서 컨트랙트를 컴파일 + 배포하는 과정에서 에러가 발생한다.
Truffle migrate Error You must specify a network id in your development configuration in order to use this network
에러의 내용은 Truffle에서 컴파일 후 배포할 네트워크를 지정해주지 않았다는 것이다.
Solved
truffle-config.js 파일에 들어가서 현재 배포할 네트워크 설정이 정상적으로 되어 있는지 확인한다. 만약 배포할 네트워크의 network_id를 모른다면 '' 빈 문자열이라도 입력해야 에러가 해결된다. 하지만 네트워크를 명시하지 않으면 컴파일 된 컨트랙트가 갈 방향이 안잡히기 때문에 해당 블록체인의 id를 찾아봐야 된다.
Klaytn Baobab 테스트넷 네트워크 ID는 1001 번이다. truffle-config.js 파일에서 네트워크를 다음과 같이 설정해주고 다시 migrate를 진행한다.
networks : {
baobab: {
provider: () => new HDWalletProvider(mnemonic, "https://api.baobab.klaytn.net:8651"),
network_id: '1001', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice: null
},
}
이제 정상적으로 컴파일 및 배포가 완료 된다.