In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to compile the Ethernet Square Intelligent contract written by solidity through solc". In the operation of the actual case, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Compiler of solc:solidity
The ethernet square intelligent contract written by solidity can be compiled by the command line compiler tool solc to become the code in the etherfang virtual machine. Solc is compiled and eventually deployed on the chain to form the various smart contracts we have seen.
As a solidity command-line compiler, let's take a look at what the official website says about solc.
Installation of solc is simple:
Npm install-g solc// or npm install-g solc-cli// or sudo apt-get install solc
After the installation is complete, the solc-- help,solc-- help command displays all the solc command options. The compiler can generate a variety of outputs, such as the final binary contract file, the assembly of the grammar tree, or the expected cost of gas. 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 sourceFile.sol.
You can optimize it with solc-optimize-bin sourceFile.sol before deploying the ethersquare smart contract. By default, the solc compiler will help you optimize 200 times. You can also set-- runs=1 to compile in a minimized way, and if you want multiple transactions to care less about cost, you can set it to the number of times you want:).
The command line compiler automatically reads the files that need to be imported, or you can specify the path by using prefix = path, for example:
Solc github.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/ = / usr/local/lib/fallback file.sol
The compiler will start the search in the / usr/local/lib/dapp-bin/ directory under the specified directory github.com/ethereum/dapp-bin/, and if no files are found, it will look at / usr/local/lib/fallback. Solc will only read the two paths you specify, so it looks like import "/ etc/passwd"; it must be remapped through / = to work. If there is more than one match, select the one with the longest common prefix to match.
For security reasons, the compiler limits some of the directories it can access. Everything other than the path of the source file specified on the command line (and its subdirectories) and the path specified on the command line is rejected. -allow-paths / sample/path,/another/sample/path to switch.
If the smart contract uses libraries, you will notice that the bytecode contains a substring of _ _ LibraryName_. You can use solc as the linker, which means it will insert the library address for you at these points.
You can add a 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 run solc with-- libraries fileName.
If Solc is called with the option-- link, all input files are interpreted as unlinked binaries (HEX encoding), linked to the appropriate address in the _ _ LibraryName____ format given above (or written to stdout if input is read from stdin). In this case, all options except the library are ignored (including-o).
If you call SOLC with-- standard-json, it takes the standard JSON input (described below) and returns the JSON output.
# solc compiler input and output JSON description
These JSON formats are used by the compiler API and are available through SOLC. The content is modifiable, and some objects are optional (as mentioned earlier) for backward compatibility.
The compiler's API requires an input in JSON format, and then outputs the compilation result in JSON format.
Note that comments are not allowed. The comments in the following example are made on the official website for learners to better understand the annotations.
Enter a description of the format:
{/ / Required: Source code language, such as "Solidity", "serpent", "lll", "assembly", etc. Language: "Solidity", / / Required sources: {/ / The keys here are the "global" names of the source files, / / imports can use other files via remappings (see below). MyFile.sol: {/ / Optional: keccak256 hash of the source file / / It is used to verify the retrieved content if imported via URLs. "keccak256": "0x123...", / / Required (unless "content" is used, see below): URL (s) to the source file. / / URL (s) should be 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 be raised. "urls": ["bzzr://56ab...", "ipfs://Qma...", "file:///tmp/path/to/file.sol"]}," mortal ": {/ / Optional: keccak256 hash of the source file" keccak256 ":" 0x234... " / / Required (unless "urls" is used): literal contents of the source file "content": "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 how many times you intend to run the code. / / Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage. Runs, 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 are 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 are used, this source file should match the global path after remappings were applied. / / If this key is an empty string, that refers to a global level. "myFile.sol": {"MyLib": "0x123123..."} / / The following can be used to select desired outputs. / / If this field is omitted, then the compiler loads and does type checking, but will not generate any outputs apart from errors. / / The first level key is the file name and the second is 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 are as follows: / / abi-ABI / / ast-AST of all source files / / legacyAST-legacyAST of all source files / / devdoc-Developer documentation (natspec) / / userdoc-User documentation (natspec) / / metadata-Metadata / / ir-New assembly format before desugaring / / evm.assembly-New assembly format after desugaring / / evm.legacyAssembly-Old-style assembly format in JSON / / evm.bytecode.object-Bytecode object / / evm.bytecode.opcodes-Opcodes list / / 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-Function 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. Will select every / / target part of that output. Additionally, `*` can be 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 within the source file. SourceLocation: {file: "sourceFile.sol", start: 0, end: 100], / / Mandatory: Error type, such as "TypeError", "InternalCompilerError", "Exception", etc. / / See below for complete list of types. Type: "TypeError", / / Mandatory: Component where the error originated, such as "general", "ewasm", etc. Component: "general", / / Mandatory ("error" or "warning") severity: "error", / / Mandatory message: "Invalid keyword" / / Optional: the message formatted with source location formattedMessage: "sourceFile.sol:100: Invalid keyword"}], / / This contains the file-level outputs. In can be limited/filtered by the outputSelection settings. Sources: {"sourceFile.sol": {/ / Identifier (used in source maps) id: 1, / / The AST object ast: {}, / / The legacyAST object legacyAST: {}}, / / This contains the contract-level outputs. It can be limited/filtered by the outputSelection settings. Contracts: {"sourceFile.sol": {/ / If the language used has 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 (serialised 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 as 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 20 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"} External: {"delegate (address)": "25000"}, internal: {"heavyLifting ()": "infinite"}, / / eWASM related outputs ewasm: {/ / S-expressions format wast: "" / / Binary format (hex string) wasm: ""}
Error type description:
JSONError:JSON error, JSON input does not conform to the required format, such as input is not a JSON object, language is not supported, and so on.
IOError:IO error, IO, and import handling error, such as unresolvable URL or hash mismatch in the supplied source.
ParserError: syntax f parsing error, source code does not conform to the language rules.
DocstringParsingError: document parsing error, unable to parse the NATSPEC tag in the comment block.
SytRealError: syntax errors, such as the use of continue outside the for loop.
DeclarationError: an incorrectly declared, invalid, unresolvable, or conflicting identifier name. For example, no identifier was found
TypeError: type error, such as invalid type conversion, invalid assignment, etc.
UnimplementedFeatureError: this feature is not supported by the compiler, but is expected to be supported in a future release.
InternalCompilerError: internal errors are triggered in the compiler, which should be reported as a problem.
Exception: exception, unknown failure during compilation, which should be used as a problem feedback.
CompilerError: compilation error, invalid use of compiler stack, which should be reported as a problem.
FatalError: fatal error, which should be fed back as a problem.
Warning: the warning does not stop compilation, but should be addressed if possible.
This is the end of the content of "how to compile the Ethernet Square Smart contract written by solidity through solc". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.