Solidity

編譯錯誤:@openzeppelin/contracts/token/ERC20/ERC20.sol:205:9:ParserError:預期的主要表達式。未選中 { ^——–^

  • November 9, 2022

函式減少允許(地址花費者,uint256 減去值)公共虛擬返回(布爾){地址所有者 = _msgSender();uint256 currentAllowance = 津貼(所有者,支出者);要求(currentAllowance>=subtractedValue,“ERC20:減少零以下的津貼”);未選中 { _approve(所有者,支出者,currentAllowance - 減值);}

   return true;
}

您是否使用大於 0.8 的 pragma solidity?

未選中對於 0.8 之前的 Solidity 版本不是問題,因此您的 pragma solidity 必須為 0.8.0 或更高版本

我假設這個簡短的例子是由於 ProxyFactory 合約可能導致 與您的智能合約不匹配,但無論如何,這個配置對我來說是:Solidity

如果您想要直接部署可升級合約,我可以推薦使用**OpenZeppelin 升級外掛**for Truffleand Buidler.

要通過factory部署可升級合約,您可以proxy在 OpenZeppelin Contracts 中部署(Solidity 0.6或者Solidity 0.7)。

代理合約從OpenZeppelin Contracts 3.2中的 OpenZeppelin SDK 移出

pragma solidity ^0.7.0;

import "./UpgradeableProxy.sol";

/**
* This contract implements a proxy that is upgradeable by an admin.
* 
* To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
* clashing], which can potentially be used in an attack, this contract uses the
* https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
* things that go hand in hand:
* 
* 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
* that call matches one of the admin functions exposed by the proxy itself.
*
* 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the
* implementation. If the admin tries to call a function on the implementation it will fail with an error that says
* "admin cannot fallback to proxy target".
* 

引用自:https://ethereum.stackexchange.com/questions/139092