# solc:solidity's compiler solidity the Ethereum smart contract written by the command-line compiler tool SOLC to compile and become the code in the Ethereum virtual machine. Solc is compiled and eventually deployed to the chain to form the various smart contracts we see. As a solidity command-line compiler tool, let's take a look at what the official website says Solc. The installation of SOLC is simple: "' npm install-g solc//or npm install-g solc-cli//or sudo apt-get install Solc ' ' after installation we see, ' Solc--help ', The Solc--help command displays all the SOLC command options. The compiler can generate various kinds of output, such as the final binary contract file, the compilation of the syntax tree, or the gas that is expected to be spent. ' ' Solc--bin sourcefile.sol ', you can compile and output a smart contract file called Sourcefile.sol. If you want to get richer output variables from ' Solc ', you can use ' Solc-o outputdirectory--bin--ast--asm '. You can use ' Solc--optimize--bin Sourcefile.sol ' before deploying [Ethereum Smart Contract] (HTTP://XC.HUBWIZ.COM/COURSE/5A952991ADB3847553D205D1) ' Optimize it. By default, the SOLC compiler will help you optimize 200 times. You can also set the '--runs=1 ' so that it compiles in a minimized way, and if you want multiple trades to be less cost-conscious, you can set the number of times you want:). The command-line compiler will automatically read the files that need to be imported, or you can specify the path by using ' prefix = Path ', such as:> ' Solc github.com/ethereum/dapp-bin/=/usr/local/lib/ dapp-bin/=/usr/local/lib/fallback File.sol "" This will cause the compiler to "/usr/local/lib" from the specified directory "github.com/ethereum/dapp-bin/" /dapp-bin/' ' Directory starts the search, and if no file is found, it will look at '/usr/local/lib/fallback '. SOLC will only read your specifiedThese two paths, so like "import"/etc/passwd ";" must be re-mapped by '/= ' to work. If there are multiple matches, select the match with the longest common prefix. For security reasons, the compiler restricts some of the directories it can access. All content other than the path (and its subdirectories) of the source file specified on the command line and the path specified by the command line will be rejected. "'--allow-paths/sample/path,/another/sample/path ' to switch." If the smart contract uses [libraries] (https://solidity.readthedocs.io/en/v0.4.24/contracts.html#libraries), you will notice that the bytecode contains ' __ ' A substring of libraryname______ '. You can use SOLC as the linker, which means that it will plug you into the inbound address at these points. You can add the library "--libraries" math:0x12345678901234567890 heap:0xabcdef0123456 "" to your command to provide the address of each library, or use the description string in the file (one library per line), and use '--libraries fileName ' to run SOLC. If you call Solc with the option '--link ', all input files are interpreted as unlinked binaries (hex code), and in the "__libraryname____" format given above, link them to the appropriate address (if the input is read from stdin, Write it to stdout). In this case, all options except the library are ignored (including '-O '). If you call Solc with '--standard-json ', it will enter the standard JSON input (described below) and return the JSON output. #solc编译器输入输出JSON描述这些JSON格式通过编译器API使用, can be obtained by SOLC. The content can be modified, and some objects are optional (as described earlier) and are intended for backwards compatibility. The compiler's API requires a JSON-formatted input and then outputs the compiled results in JSON format. * * Note that annotations are not allowed * *. The note in the following example is the official website for learners to better understand the annotation. * Input Format Description: ' ' {//Required:source code language, such as "solidity", "Serpent", "lll", "assembly", etc. lAnguage: "Solidity",//Required sources: {//The keys here is the "global" names of the source files,//imports can US e Other files via remappings (see below). "Myfile.sol": {//optional:keccak256 hash of the source file//It's used to verify the retrieved content if imported V IA URLs. "keccak256": "0x123 ...",//Required (unless "content" is used, see below): URL (s) to the source file. URL (s) should is imported in this order and the result checked against the//keccak256 hash (if available). If the hash doesn ' t match or none of the//URL (s) result in success, an error should is raised. "URLs": ["Bzzr://56ab ...", "Ipfs://qma ...", "File:///tmp/path/to/file.sol"]}, "mortal": {//optional:keccak256 hash O f The source file "keccak256": "0x234 ...",//Required (unless "URLs" is used): literal contents of the source file "Conte NT ":" Contract mortal is owned {function Kill () {if (Msg.sender = = owner) selfdestruct (owner);}} "} },//Optional settings: {//Optional:sorteD List of remappings remappings: [": G/dir"],//Optional:optimizer settings Optimizer: {//disabled by default enabled : true,//Optimize for what many times you intend to run the code. Lower values would optimize more for initial deployment cost, higher values would optimize more for high-frequency usage. RUNS:200}, Evmversion: "Byzantium",//Version of the EVM to compile for. Affects type checking and code generation. Can be Homestead, Tangerinewhistle, Spuriousdragon, Byzantium or Constantinople//Metadata settings (optional) Metadata: {//Use only literal content and not URLs (false by default) Useliteralcontent:true},//Addresses of the libraries. If not all libraries was given here, it can result in unlinked objects whose output data is different. Libraries: {//The top level key is the the name of the source file where the library is used.//If remappings is used, This source file should match the global path after remappings were applied. If This key was an EMPTy string, that's refers to a global level. "Myfile.sol": {"Mylib": "0x123123 ..."}} The following can used to select desired outputs. If This field was omitted, then the compiler loads and does type checking, but would not generate any outputs apart from Errors. The first level key is the file name and the second are the contract name, where empty contract name refers to the file itself,//While the Star refers to all of the contracts. The available output types is as follows://Abi-abi//Ast-ast of all source files//legacyast-legacy ast O F All source files//Devdoc-developer documentation (NATSPEC)//Userdoc-user documentation (NATSPEC)//Metadata-m Etadata//ir-new assembly format before desugaring//evm.assembly-new assembly format after desugaring//evm.legacy Assembly-old-style Assembly format in JSON//Evm.bytecode.object-bytecode object//Evm.bytecode.opcodes-opcodes Li ST//Evm.bytecode.sourcemap-source Mapping (useful for Debugging)//Evm.bytecode.linkreferences-link references (if unlinked object)//evm.deployedbytecode*-Deployed bytecode (Has the same options as Evm.bytecode)//evm.methodidentifiers-the list of function hashes//EVM.GASESTIMATES-FUNCT Ion gas estimates//ewasm.wast-ewasm s-expressions format (not supported ATM)//EWASM.WASM-EWASM binary format (not Supported ATM)////Note that using a using ' EVM ', ' evm.bytecode ', ' ewasm ', etc. 'll select every//target part of the Output. Additionally, ' * ' Can is used as a wildcard to request everything. Outputselection: {//Enable the metadata and bytecode outputs of every single contract. "*": {"*": ["Metadata", "Evm.bytecode"]},//Enable the ABI and opcodes output of Mycontract defined in file def. "Def ": {" mycontract ": [" Abi "," Evm.bytecode.opcodes "]},//Enable the source map output of every single contract." * ": {" * ": [" Evm.bytecode.sourceMap "]},//Enable The legacy AST output of every single file. "*": { "": ["Legacyast"]} }}} ' * Output format description ' ' {//Optional:not present if no errors/warnings were encountered errors: [{//Optional:location with In the source file. Sourcelocation: {file: "Sourcefile.sol", start:0, end:100],//mandatory:error type, such as "TypeError", "Internalco Mpilererror "," Exception ", etc.//See below for the complete list of types. Type: "TypeError",//Mandatory:component where the error originated, such as "General", "ewasm", etc. Component: "Genera L ",///Mandatory (" error "or" warning ") Severity:" Error ",//Mandatory message:" Invalid keyword "//optional:the Messag E formatted with source location formattedmessage: "Sourcefile.sol:100:invalid keyword"}],//This contains the File-le Vel outputs. In Can is limited/filtered by the outputselection settings. Sources: {"Sourcefile.sol": {//Identifier (used in source maps) Id:1,//The AST object AST: {},//The Legacy AST obj ECT legacyast: {}}},//This contains the contract-level outputs. It can be limitEd/filtered by the outputselection settings. Contracts: {"Sourcefile.sol": {//If the language used have no contract names, this field should equal to an empty string . "Contractname": {//the Ethereum contract ABI. If empty, it is represented as an empty array. See Https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI ABI: [],//See the Metadata Output documentation (SER ialised JSON String) metadata: "{...}",//User documentation (NATSPEC) Userdoc: {},//Developer documentation (NATSPEC) Devdoc: {},///Intermediate representation (String) IR: "",//evm-related outputs EVM: {//Assembly (String) Assembly: " ",///Old-style Assembly (object) legacyassembly: {},//bytecode and related details. Bytecode: {//The bytecode as a hex string. Object: "00fe",//Opcodes list (string) opcodes: "",//the source mapping a S a string. See the source mapping definition. Sourcemap: "",//If Given, this is an unlinked object. Linkreferences: {"Libraryfile.sol": {//Byte offsets into The bytecode. Linking replaces the bytes located there. "Library1": [{start:0, length:20}, {start:200, length:20}]}},//the same layout as above. Deployedbytecode: {},//The list of function hashes Methodidentifiers: {"Delegate (address)": "5c19a95c"},//function Gas estimates Gasestimates: {creation: {codedepositcost: "420000", Executioncost: "Infinite", TotalCost: "Infinite"}, E Xternal: {"Delegate (address)": "25000"}, internal: {"heavylifting ()": "Infinite"}}},//ewasm related outputs ewasm: {//S-expressions format wast: "",//Binary format (hex string) wasm: ""}}}} "* Error type Description: 1. Jsonerror:json error, JSON input does not conform to the required format, such as input is not JSON object, language is not supported, and so on. 2. Ioerror:io error, IO and import processing errors, such as unresolved URLs in the supplied source or hash mismatch. 3. ParserError: Syntax f parsing error, source code does not conform to language rules. 4. Docstringparsingerror: Document parsing error, unable to parse Natspec tag in comment block. 5. Sytrealerror: syntax error, such as ' Continue ' is used outside the ' for ' Loop. 6. Declarationerror: Declared error, invalid, unresolved, or conflicting identifier name. For example, identifier 7 was not found. TypeError: Type error, such as invalid type conversion, invalid assignment, and so on. 8. Unimplementedfeatureerror: The compiler does not support this feature, but I hope that in the futureSupported in the release. 9. Internalcompilererror: The compiler triggers an internal error, which should be fed back as a problem. Exception: exceptions, unknown failures during compilation, which should be feedback as a problem. CompilerError: Compile error, invalid use of compiler stack, this should be feedback as a problem. FatalError: Fatal error, which should be feedback as a problem. Warning: Warnings do not stop compiling, but should be handled if possible. Please visit: [Solc] (http://blog.hubwiz.com/2018/06/14/solc-compiler/) If you want to start learning Ethereum dapp Development immediately, it is recommended to visit an online tutorial: * [Ethereum Smart Contract] (http ://xc.hubwiz.com/course/5a952991adb3847553d205d1?affid=studygolang616), mainly introduces intelligent contract and DAPP application development, suitable for getting started. * [Ethereum Development] (http://xc.hubwiz.com/course/5abbb7acc02e6b6a59171dd6?affid=studygolang616), mainly introducing the use of node. js, MongoDB, Blockchain , IPFs realize to the center of e-commerce Dapp actual combat, suitable for advanced. 281 reads
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.