Solidity

ParserError:預期的編譯指示、導入指令或契約/介面/庫定義

  • October 2, 2020

在嘗試編譯我的 ABI 並驗證我的契約時,我收到以下警告:“ParserError: Expected pragma, import directive or contract /interface/library definition”在第一行,如圖所示。請幫助我克服這個障礙。我的ABI原始碼如下:pragma solidity ^0.5.8; 導入“github.com/oraclize/ethereum-api/oraclizeAPI.sol”;

{
^ "contractName": "Salemcash",
 "abi": [
{
 "inputs": [],
 "payable": false,
 "stateMutability": "nonpayable",
 "type": "constructor" 
}, {
 "constant": true,
 "inputs": [
   {
     "name": "account",
     "type": "address"
   }
 ],
 "name": "getBalance",
 "outputs": [
   {
     "name": "",
     "type": "uint256"
   }
 ],
 "payable": false,
 "stateMutability": "view",
 "type": "function"
}, {
  "name": "gulp-solidity-abi",
  "version": "0.0.3",
  "description": "Gulp plugin to extract the ABI from Solidity contract",
  "scripts": {
  "coverage": "nyc _mocha",
  "test": "mocha"
},
  "repository": {
  "type": "git",
  "url": "git+https://github.com/PastorOmbura/SalemCash"
},
  "keywords": [
   "Salemcash", 
   "gulpplugin",  
   "solidity",
   "abi",
   "gulp",
   "plugin"
],
  "author": {
  "name": "Pastor Ombura",
  "email": "alex.ombura@gmail.com",
  "url": "http://salemcash.org/"
},
  "license": "The LevelDB Authors",
   "bugs": {
   "url": "https://github.com/PastorOmbura/SCS/blob/1800dc20e583c129542d5306a5efd499d04b0e66/build-windows.md"
},
  "homepage": "https://github.com/PastorOmbura/SCS#readme",
  "devDependencies": {
  "chai": "4.1.2",
  "chai-string": "1.5.0",
  "gulp": "4.0.0",
  "gulp-rename": "1.4.0",
  "mocha": "5.2.0",
  "mocha-lcov-reporter": "1.3.0",
  "nyc": "13.1.0",
  "vinyl-fs-fake": "^1.1.1"
}, 
 "constant": false,
 "inputs": [
    {
     "name": "to",
     "type": "address"
   },
   {
     "name": "amount",
     "type": "uint256"
   },
{
 "name": "transfer",
 "outputs": [],
 "payable": false,
 "stateMutability": "nonpayable",
 "type": "function"
}]

您無法編譯 ABI。該錯誤是因為 Solidity 編譯器希望看到 Solidity 程式碼,但它卻看到了其他內容 (JSON)。

更改您正在使用的solidity 版本。將您的solidity文件的第一行更改為此

pragma solidity >0.4.2;

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