Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient
본문 바로가기
ERROR

Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient

by 쏠수있어ㅤ 2022. 8. 20.
반응형

 

 

Remix Ethereum IDE 로 간단한 solidity smart contract를 연습하다가 나온 에러 

 

Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient

 

이 에러는 a visibility specifier 중 하나인 public이 constructor에 아무 효과가 없다는 것을 말하고 있는 것이다. 

Constructor 는 해당 contract가 처음 배포될 때 단 한번 실행되고 이후에 다시 실행될 수 없다. 때문에 "visible" 을 가리키는 public은 사용하지 않아도 된다는 의미이다. 

 

* Abstract contracts 는 constructor 자체가 없다. 

 

해결 방법 

=> constructor에 "public" 을 제거했다. 

 

 

에러 없이 잘 배포된 contract 👇

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

contract PracticeMakingCoins {
    mapping (address => uint256) public coinBalance;

    constructor() payable {
        coinBalance[msg.sender] = 1000000000000000;
    }

    function transfer(address _to, uint256 _amount) public payable {
        // require(coinBalance[msg.sender] >= _amount);

        coinBalance[msg.sender] -= _amount;
        coinBalance[_to] += _amount;
    }
}

 

 

 

Reference : https://ethereum.stackexchange.com/questions/98453/visibility-for-constructor-is-ignored-if-you-want-the-contract-to-be-non-deploy

반응형

댓글