체인의정석

payable 사용시 발생하는 에러 ParserError: Expected primary expression. 본문

블록체인/Solidity

payable 사용시 발생하는 에러 ParserError: Expected primary expression.

체인의정석 2022. 8. 11. 13:40
728x90
반응형

0.5.0 버전의 코드로 작업중이 였는데 payable을 다루는 과정에서 컴파일 에러가 발생하였다.

에러의 원인은 바로 solidity 버전이 0.5.0 버전 이상이 되면서 주소값을 payable로 지정해 주어야 하는데 payable을 사용하면 다음과 같은 에러가 발생하는 것.

 

많은 외국인들도 동일한 문제로 헤매고 있는것 같다. 비슷한 케이스에 대한 결과가 다수 확인되었다. 읽어본 결과 여기에 대한 해결책은 다음과 같다.

 

1. payable 대신에 call에다가 value를 입려서 쓴다. (low level call은 address payable이 아니여도 가능)

2. solidity를 0.6.0 버전 이상으로 올려준 후 컴파일러에서도 맞추어 주면 된다고 한다. (Solidity 버전을 올려야 함)

 

 

그 외의 관련된 자료들을 하단에 정리해 두었다.

 

https://ethereum.stackexchange.com/questions/64108/whats-the-difference-between-address-and-address-payable/64109#64109

 

What's the difference between 'address' and 'address payable'?

I saw a Solidity smart contract where some variables were declared with the type address and some were declared with the type address payable. What are the differences between the two? Do they sto...

ethereum.stackexchange.com

Built-in methods

You can use .transfer(..) and .send(..) on address payable, but not on address.

You can use a low-level .call(..) on both address and address payable, even if you attach value.


Casting from address payable to address

address payable can be implicitly or explicitly cast to address:

address payable addr1 = msg.sender;
address addr2 = addr1; // This is correct
address addr3 = address(addr1); // This is correct

Casting from address to address payable

address can only be explicitly cast to address payable:

address addr1 = msg.sender;
address payable addr2 = addr1; // Incorrect
address payable addr3 = address(uint160(addr1)); // Correct since Solidity >= 0.5.0
address payable addr4 = payable(addr1); // Correct since Solidity >= 0.6.0

Casting address[] or address payable[]

Although a single address payable can be cast to address, arrays of one address type cannot be cast to arrays of another address type:

function testCast(address payable[] memory _addresses) returns (address[] memory)
{
    return _addresses; // Type error!
}

 

 

https://ethereum.stackexchange.com/questions/84155/parsererror-expected-primary-expression-address-payable-payable

 

ParserError: Expected primary expression - address payable - payable()

I'm trying to get myself familiarized with ethereum. So I was going through a repo, and tried to rum the code : function transferFundOnResolve(uint cid) private { // Could also be used:

ethereum.stackexchange.com

 

728x90
반응형
Comments