Giter VIP home page Giter VIP logo

vscode-solidity's Introduction

Solidity support for Visual Studio code

Version Downloads Installs Rating

Solidity is the language used in Ethereum to create smart contracts, this extension provides:

  • Syntax highlighting
  • Snippets
  • Compilation of the current contract (Press F1 Solidity : Compile Current Solidity Contract), or F5
  • Compilation of all the contracts (Press F1 Solidity : Compile all Solidity Contracts), or Ctrl + F5 or Cmd + F5
  • Code completion for all contracts / libraries in the current file and all referenced imports
  • Goto definition
  • Find all references in project
  • Hover information
  • Code actions / quick fixes (change compiler, format address, add sdpx license.. )
  • Mono repo support (identifies the project by finding the files: remappings.txt, foundry.toml, brownie-config.yaml, truffle-config.js, hardhat.config.js, hardhat.config.ts)
  • Default project structure (solidity files needs to be in the src/ directory, and libraries in the lib/ directory). Libraries will follow the same structure.
  • Compilation supporting EIP82 (dappfile and dependency packages)
  • Support for different solidity versions (Remote and local)
  • Download source code and Abi from Etherscan
  • Code generation using Nethereum, it includes currently the default template for Nethereum service, dtos generation. (Open 'contractName.json' after compilation from the bin folder. Press F1 and press Solidity: Code generate from compilation output..) Auto generation of Nethereum files on compilation
  • Linting using Solhint or Ethlint

It is also available as a standalone LSP:

npm install -g vscode-solidity-server
vscode-solidity-server --stdio

Instructions

Using a different version of the solidity compiler

Sometimes you may want to use a different compiler than the one provided. You can find all the different versions in the solc-bin repository https://binaries.soliditylang.org/

Currently we support four ways supported to use a different version of the solidity compiler. Remote, Local, NodeModule and Embedded

You can change the compiler, in your user settings or workspace settings.

image

Remote download

When selecting remote download the compiler gets downloaded from the solc-bin repository.

You will need to change the following user setting, with the version required, for example 'latest' or 'v0.8.18+commit.87f61d96', for your workspace user setting (current project) or global user setting (all projects)

"solidity.compileUsingRemoteVersion" : "latest"

Screenshot

You can simply change this setting using the context menu:

Screenshot

Screenshot

Using a code action

If your code is targetting a specific version for solidity, and see the issue highlighted you can also trigger the menu directly from the import.

Screenshot

Using a Local file

If you want to keep a compiler version locally, you can download the compiler from https://binaries.soliditylang.org/ and change your user settings to use this.

"solidity.compileUsingLocalVersion" : "C:\\Users\\JuanFran\\Downloads\\soljson-v0.8.18%2Bcommit.87f61d96.js"

The simplest way to download a compiler is to use the context menu, this will download your desired version at the root of the project and configure your workspace accordingly.

image

Npm / node installation

Another option, is to use the solc npm package in your project, if this is enabled it will try to find the compiler in your configured node_modules at root.

You can install solc using npm at the root of your project as follows.

npm install solc 

The default module package is "solc", but you may want to use other node module containing a compiler, this can be configured in the settings: image

Compiling a specific contract using a different compiler than the default one.

There might be scenarios, that you want to use a different compiler for a specific file, using one of the other configured compilers.

image

image

ERC, ERC drafts and Smart contracts snippets / reference

It is pretty hard sometimes to find interfaces or information about an EIP (ERC) or specific libraries to simply get started working with Solidity. The solidity extension now includes ERC approved and most drafts (wip) to help get you started.

Just type erc and select the erc example or interface you want.

Screenshot Screenshot

Smart contract project interfaces

In a similar to way to ERCs and as we work towards to more interoperable smart contracts, being able to quickly examine those interfaces that you want to integrate is a time saver.

The current release includes the interfaces for Uniswap V2 (to get started), just type uni to list them all. Screenshot Screenshot

Note: If an ERC or your project is not included, please create a pull request. Note: Only established projets will be included.

Compiler optimization

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. The default value is 200. "solidity.compilerOptimization": 200

Project structure and Remappings

Mono repo support

Mono repo support enables having different projects in the same workspace as opposed to different open workspaces in the same window.

To provide mono repo support, idenfify the project by finding one of the files used by different tools, for example remappings.txt, foundry.toml, brownie-config.yaml, truffle-config.js, hardhat.config.js. Solidity does not have a standard project file yet, or many not have it ever, so this is the best solution.

The settings enable Mono repo support by default, but if wanted can be disabled.

Dependencies for both "Node_modules" and "Lib" (Default)

If you're using a library like @openzeppelin/contracts, the OpenZeppelin Contracts will be found in your node_modules folder, or you might be using a library like Solmate and you might put it in your lib folder. So the user settings will be the following, assuming your solidity project is at root.

This is the default now, so you don't need to set it.

  "solidity.packageDefaultDependenciesContractsDirectory": "",
  "solidity.packageDefaultDependenciesDirectory": ["node_modules", "lib"],

If you have a deeper structure, like

Solution
└───solidity_project
│   │
|   │   xx.sol
│   └───node_modules
│   
└───Nethereum_Project
|   │   xx.cs
|   │   yy.cs
|
└───Web3Js_Project
|   │   xx.js
|   │   yy.js

Your user settings configuration will need to represent the full structure:

  "solidity.packageDefaultDependenciesContractsDirectory": "",
  "solidity.packageDefaultDependenciesDirectory": "solidity_project/node_modules"

Dappsys (old ERC)

The project / library dependency structure can use the DappSys library model, this was the default mode before as it was part of an ERC:

Screenshot

Libraries will have the same name as their folder they are included. Solidity files will be in the 'src' folder. Libraries will be included in the 'lib' folder.

Currently there is no name conflicting resolution, so the first library found matching a name, will be the first one used.

The user settings for this structure is:

  "solidity.packageDefaultDependenciesContractsDirectory": "src",
  "solidity.packageDefaultDependenciesDirectory": "lib"

Resolving imports from different contract directories shortcuts

There are projects that may have their contracts in the "contracts" directory or you may have a mixture of them that are both in "contracts", "src" or just not specific shortcut. For this the extension internally tries to resolve these generic shortcuts if an import is not found. The default are ["contract", "src", ""]

This behaves in the same way as "solidity.packageDefaultDependenciesDirectory": "lib". If you see there is a need for other folder names shortcuts, raise an issue.

Remappings

Another option is to use remappings to define where your dependency libraries are, this can be achieved using the settings or creating a "remappings.txt" file in the root folder. For more info on remappings check the solidity documentation here https://docs.soliditylang.org/en/latest/path-resolution.html?highlight=remapping#import-remapping

If you want to use the solidity user settings for your workspace / global remappings, please include them in the solidity.remappings

"solidity.remappings": [
    "@chainlink/=/Users/patrick/.brownie/packages/smartcontractkit/[email protected]",
    "@openzeppelin/=/Users/patrick/.brownie/packages/OpenZeppelin/[email protected]"
  ]

Or if you want to include them in the remappings.txt file, just put the file at the root of your project folder. Note: These will override your solidity settings if included image

Platform specific remappings

There are situations when cross-platform paths are needed, in this case you can use the solidity.remappingsWindows or solidity.remappingsUnix settings.

  "solidity.remappingsWindows": [
    "@openzeppelin/=C:/Users/<USERNAME>/.brownie/packages/OpenZeppelin/[email protected]"
  ],
  
  "solidity.remappingsUnix": [
    "@openzeppelin/=/Users/<USERNAME>/.brownie/packages/OpenZeppelin/[email protected]"
  ]
  <<<OR>>> 
  "solidity.remappingsUnix": [
    "@openzeppelin/=/home/<USERNAME>/.brownie/packages/OpenZeppelin/[email protected]"
  ]

Code completion

Autocomplete is generally supported across for smart contracts, structs, functions, events, variables, using, inheritance. Autocomplete should happen automatically or press Ctrl+Space or Command+Space in areas like "import".

Screenshot

Auto compilation and error highlighting

Auto compilation of files and error highlighting can be enabled or disabled using user settings. Also a default delay is implemented for all the validations (compilation and linting) as solidity compilation can be slow when you have many dependencies.

"solidity.enabledAsYouTypeCompilationErrorCheck": true,
"solidity.validationDelay": 1500

Go To definition

To navigate to a definition, just press F12 or Ctrl + click to find a definition and navigate to it.

Hover information

To find more information about a method, function, variable, contract etc, you can just hover over it with your mouse. Natspecs and comments are extracted for all types to provide you all the documentation required.

Screenshot

Goto references

To find all usages of a specific type, method, etc you can press Shift + F12 or right click to find all references

Screenshot

Code actions / quick fixes

The extension provides some code actions and quick fixes, like change compiler, format address, add sdpx license, feel free to make pull requests with new ones!

Screenshot

Download source code and ABI from Etherscan

To download verified source code from Etherscan, you can right click on the folder area or in a soldity file. First select what chain the smart contract it(for example Ethereum) and then input the smart contract address. The source code will be saved in the root folder of your project. Please note that remappings will be generated for multiple files, so these might conflict with existing ones.

Screenshot

Solparse-Exp

The extension uses https://github.com/juanfranblanco/solparse-exp as the main parser, this continues the work that many have done over the years. Tim Coulter, @cgewecke, @duaraghav8 @federicobond, as a Peg solidity parser in javascript.

Linting

There are two linters included with the extension, solhint and solium / ethlint. You can chose your preferred linter using this setting, or disable it by typing ''

Screenshot

Solhint

To lint Solidity code you can use the Solhint linter https://github.com/protofire/solhint, the linter can be configured it using the following user settings:

"solidity.linter": "solhint",
"solidity.solhintRules": {
  "avoid-sha3": "warn"
}

This extension supports .solhint.json configuration file. It must be placed to project root directory. After any changes in .solhint.json it will be synchronized with current IDE configuration.

This is the default linter now.

NOTE: Solhint plugins are not supported yet.

Solium / Ethlint

Solium is also supported by the extension https://github.com/duaraghav8/Solium, you can configure it using the following user settings:

"solidity.linter": "solium",
"solidity.soliumRules": {
    "quotes": ["error", "double"],
    "indentation": ["error", 4]
},

Formatting using Prettier and the Prettier Solidity Plugin

Formatting is provided thanks to the Prettier plugin for Solidity for more info check https://prettier.io/ and https://github.com/prettier-solidity/prettier-plugin-solidity

Formatting uses the default formatting settings provided by prettier, if you want to provide your custom settings create a .prettierrc file as follows

{
  "overrides": [
    {
      "files": "*.sol",
      "options": {
        "printWidth": 80,
        "tabWidth": 4,
        "useTabs": true,
        "singleQuote": false,
        "bracketSpacing": true,
        "explicitTypes": "always"
      }
    }
  ]
}

ℹ️ Settings are applied immediately on the latest version of the plugin. If your settings are not reflected immediately consider updating to the latest version, if it still doesn't work please restart visual studio code.

If you would like to format on save, add this entry to your user / workspace settings:

"editor.formatOnSave": true

Formatting using forge fmt

Formatting can also be performed with forge fmt by Foundry. You can configure it using a foundry.toml in your project directory as explained in the Foundry book and then choosing forge as your formatter in the extension settings:

image

Code generation Nethereum

The extension integrates with the Nethereum code generator to create Contract integration definitions. You can either generate the api for a single contract, all compiled contracts, or automatically every time you compile a smart contract solidity file.

The simplest way to code generate a the contract definition for a smart contract is to right click and select the project / language you require:

Screenshot

Automatic code generation and the Nethereum Code generation settings file.

If you want to automatically code generate your api, every time to you compile, you can do this creating a file "nethereum-gen.settings" at the root of your project, with the following contents. You can create it automatically using the context menu too.

{
    "projectName": "Solidity.Samples",
    "namespace": "Solidity.Samples",
    "lang":0,
    "autoCodeGen":true,
    "projectPath": "../SoliditySamples"
}

"lang" indicates what language to generate the code, 0 = CSharp, 1 = Vb.Net and 3 = FSharp

The "projectName" and "namespace" settings will be used for the manual code generation also.

Use the "projectPath" to set the relative path of your .Net project, this allows to work in a "solution" mode so you can work as an both in Visual Studio Code and Visual Studio (Fat) with your .Net project, or two windows of vscode.

Abi contract code generation

You may have only the abi of a smart contract and want to code generate the contract definition. Just create a file containing the abi, with the extension .abi and another with the .bin content (if needed) and use this context menu.

Screenshot

Single smart contract manual code generation

To code generate the Nethereum contract api from a single smart contract, you need to select the compiled "json" output file from the "bin" folder, press F1 and start typing "Solidity: Code generate" and select what language you want to generate for the current selected file.

All smart contracts manual code generation

To code generate the Nethereum contract for all smart contracts already compiled, just press F1, and start typing "Solidity: Code generate" and select the option for all contracts for your desired language.

(Deprecated) Analysis of smart contracts with Mythx

Mythx analysis tool, has been moved to its own stand alone extension, please download it here.

Contributing / Issues / Requests

For ideas, issues, additions, modifications please raise an issue, if your change is significant please head to the Netherum discord for a chat https://discord.gg/u3Ej2BReNn. Note: All contributions will be under the same project license.

Credits

Many thanks to:

Christian Reitwiessner and the Ethereum team for Solidity https://github.com/ethereum/solidity, for their amazing and none stop work. Thanks to them Ethereum and all the other EVM compatible chains are they way they are. This extension piggybacks on their work.

Raghav Dua and everyone that contributed to Solium, the solidity linter, and the solidity parser.

Ilya Drabenia for creating the Solhint linter and the integration into the extension.

Nexus team for the original creation of the dappfile to structure contracts in projects https://github.com/nexusdev/dapple.

Beau Gunderson for contributing the initial integration of solium #24, the initial server and error mappings.

Mattia Richetto, Klaus Hott Vidal and Franco Victorio for creating the Prettier Solidity plugin and of course all the developers of Prettier. Please go to https://github.com/prettier-solidity/prettier-plugin-solidity for help and collaboration.

Bram Hoven for starting the multiple package dependency support for different environments (node_modules, lib)

Piotr Szlachciak for refactoring the syntaxes

James Lefrere for further refactoring the syntaxes.

Forest Fang for providing the first implementation of the "Go to definition", allowing you to navigate to structs, contracts, functions calls, etc and we have used for years.

Bernardo Vieira for adding the capability to read the solium settings from a file in the workspace root directory.

@llllvvuu for all the contributions to make the standalone language server support

Mirko Garozzo and Rocky Bernstein for the work on creating and integrating the Mythx api to analyse smart contracts (OBSOLETE NOW)

Nick Addison, Elazar Gershuni, Joe Whittles, Iñigo Villalba, Thien Toan, Jonathan Carter, Stefan Lew, Nikita Savchenko, Josh Stevens, Paul Berg for their contributions.

Sebastian Bürgel for keeping reminding me of the offline installation suppport

David Krmpotic and Ralph Pichler for the original Sublime extension https://github.com/davidhq/SublimeEthereum

Everyone for their support and feedback!

vscode-solidity's People

Contributors

beaugunderson avatar cyrusofeden avatar daniyarchambylov avatar elazarg avatar eyon42 avatar freddie71010 avatar gtonizuka avatar idrabenia avatar islishude avatar janther avatar jdonald avatar joaosantos15 avatar juanfranblanco avatar llllvvuu avatar naddison36 avatar otto-aa avatar ottodevs avatar palango avatar paulrberg avatar pizza-777 avatar purpledeerz avatar raxhvl avatar ridicoulous avatar rocky avatar rootulp avatar rostams-lyft avatar rpadaki avatar saurfang avatar shekhirin avatar sz-piotr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-solidity's Issues

pragma solidity ^0.4.17;

It looks like the current version of this is compiled for Solidity 0.4.15 so trying to use 0.4.17 causes VS Code to falsely detect issues. I'm curious as to the status update of this extension including the latest changes to Solidity (pragma version, pure and view being the current annoyances)?

No file output

Hi,

Suddenly I am no longer getting any output

The compilation is showing as successfull but no .bin nor .abi file get generated. I am just getting an empty bin folder

Any idea ?

Use local solc

I have installed solc 0.4.10. However, it seems that the extension ships with some default version that currently is at 0.4.9 (pragma solidity ^0.4.10; gives an error). I can change this version to a remote compiler version via the settings. This change requires me to be online. For train-coders like myself it would be very useful to simply use the locally installed solc in whatever version that is.

Autocomplete improvements

Autocomplete is working, but it could be better.

On struct, identify the type declared or returned by a method and do a dot completion on properties.
On contract, identify the type declared or returned by a method and do a dot completion on functions.
Methods need to identify the type returned.

Code completion for variable declararation not working

Am I the only one who don't get auto-completion for declared variables in the same file? Manually typing all variables is really bothering. I can see there is a feature Code completion for all contracts / libraries in the current file and all referenced imports in README, but it doesn't seem working.

I am using VS Code 1.22.2 in macOS High Sierra 10.13.4(17E202), with the latest extension provided(0.0.40) and I'm writing with solidity v0.4.23.

Visual Studio Code: The Solidity Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted

I am working on Win10 and getting this error from VSCode after installing the Solidity extension and then opening a .sol file:


[Error - 14:16:07] (node:10264) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Path must be a string. Received null
[Error - 14:16:07] (node:10264) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\node_modules\solc\soljson.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path")

TypeError: Path must be a string. Received null
    at assertPath (path.js:7:11)
    at Object.join (path.js:468:7)
    at createPackage (C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\out\src\projectService.js:12:35)
    at createProjectPackage (C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\out\src\projectService.js:87:26)
    at Object.initialiseProject (C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\out\src\projectService.js:33:26)
    at SolcCompiler.compileSolidityDocumentAndGetDiagnosticErrors (C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\out\src\solcCompiler.js:108:87)
    at validate (C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\out\src\server.js:36:52)
    at Timeout.setTimeout [as _onTimeout] (C:\Users\user\.vscode\extensions\JuanBlanco.solidity-0.0.27\out\src\server.js:125:26)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
[Error - 14:16:09] Connection to server got closed. Server will not be restarted.

[Feature Request] Creating a combined .sol file when compiling a contract with import's

Whenever I'm compiling a contract using Visual Studio code it generates a few files. The .bin file containing the data, the abi file containing the abi of the contract, and a json file containing metadata information and also the binary data and abi.

I then used Nethereum to upload this contract to the Ethereum blockchain. The next thing I would like to do is add the source code to the contract using Etherscan.io

However since my contracts use import statements I would have to manually copy paste all the source code into one complete .sol file to make etherscan.io understand that this includes external files.

Is this something we can possibly add as a feature to the vscode extension? (Basically generate a 4th file which contains all .sol code so that I can simply copy paste that to etherscan.io)

Using local or remote solc doesn't seem to work

As described in the documentation, I added "solidity.compileUsingRemoteVersion" or "solidity.compileUsingLocalVersion" to User Settings, but when I compile a contract, it looks like the compiler is still the latest version, not the version I specified in settings.

VSCode version 1.16.0, vscode-solidity version 0.0.29

Deployment using the configured environment settings as per EIP82

Using the configuration settings using the package file as per EIP82

environments:
  morden:
    objects:
      auth_factory1:
        class: DSAuthFactory
        address: '0x7639a37b8ecbd68e15b8e173897c6c0dea462452'

We should be able to deploy to Live, Morden, Cloud (Strato), Package Manager (npm) etc etc

What's the command line equivalent of compiling in VS Code?

I've tried the following but that doesn't give me the json files in the /bin/contracts folder
solc --bin --abi --optimize -o ./bin/contracts --overwrite ./contracts/*.sol

I tried adding the --standard-json option but it just hangs solc

My motivation is to have something like the following in my package.json file so developers who are not using VS Code can still compile my project.

"scripts": {
    "buildSol": "solc --bin --abi --optimize -o ./bin/contracts --overwrite ./contracts/*.sol",
    "buildJS": "tsc",
    "test": "jest"
  },

As you type Error highlighting

There is already an experimental implementation of this, but it has proved to be rather slow.

It will be required to implement a language server for this, which may (or not) speed up the response.

Due to the slowness of the compiler, it will be ideal if the compiler could have a global instance and a cancellation.

Help Wanted: Deploying a compiled contract

Once I have compiled a contract using this VSCode extension, I seem to be having difficulty deploying it to a local blockchain (Blockapps installed locally). When using the Visual Studio extension, deploying a contract brings up a web browser providing GUI for calling the contract on the local blockchain. Can we achieve this in some other way while using this VSCode extension?

I have tried compiling a contract and adding it to the local blockchain using bloc, but I still can't seem to find a way to test the contract through the browser or CLI (without installing the Mix IDE or Visual Studion + the Extension by ConsenSys).
Edit: Derp. Solved by adding the html extension to the URL.

Any guidance/pointer in the right direction would be helpful

Many thanks,
NellyWhads

PS. Great work in bringing solidity to VSCode - I love the lightweight editor and now love using it for this new language thanks to your efforts :)

Command 'solidity.compile.active' not found

Hello.
After recent VS Code update, I am not able to compile .sol files by pressing F5. VS Code displays error "Command 'solidity.compile.active' not found".
Ctrl+F5 gives error "Command 'solidity.compile' not found".
I feel these commands should be configured in some sort of settings file, but I don't know how.

Workflow with Truffle?

Hello. Thank you for writing this extensive Visual Code plugin for Solidity.

I'm a veteran coder but brand new to Solidity. I'm following along with the HappyFunCorp Webthereum tutorial found here:

https://happyfuncorp.com/whitepapers/webthereum

Is there a web page somewhere that talks about how to use this plugin with Truffle?

Solium Dependency Update

Hello! Thank you for writing a great plugin for VSCode.

While Solium is v1.1.5 in master branch, it is still v0.5.5 in vscode-solidity.

Will you accept pull request updating the dependency? Are there any critical parts of the plugin that may be affected?

Thank you!

I'm having trouble using the extension

I'm new to VS Code (using VS Ultimate) and have these questions:

  • How do I start? How do I create a "project" with the correct structure and default files?
  • How do I deploy (manually with Mint?)

Syntax error when line starts with commas

Hello, firstly I'd like to thank you for writing this extension!

Anyways, my small problem is as follows. The CryptoZombies tutorial includes a line which interacts the CryptoKitties getKitty function. Because we only want the last variable, the rest are left empty and we just have commas.

(,,,,,,,,, kittyDna) = kittyContract.getKitty(_kittyId);

Now, as far as I can tell this is perfectly valid Solidity code and I can even compile it with the vscode-solidity extension. However, I'm getting a rather irritating error message from the linter

Syntax error: Expected "!", "!=", "(", "+", "++", "-", "--", "0", "<", "<=", "==", ">", ">=", "[", "^", "delete", "false", "hex", "mapping", "new", "this", "true", "v", "~", [1-9], comment, end of line, identifier, number, string, or whitespace but "," found.

I could just ignore this when I was on vscode 1.19, but as of 1.20 the error is very prominent, so I'd like to find a solution.

screen shot 2018-02-14 at 21 58 24

[Solved] How to change/specify Solidity linter [solc] compiler version in Visual Studio Code?

solidity linter compiler version1
Hi may I know how to change my Solidity linter compiler version in Visual Studio Code(vscode)? OR Visual studio code how to specify solidity compiler version?

The only Solidity related extensions I have installed are solidity 0.0.38 by Juan Blanco, and Solidity Extended 3.0.2 by beaugunderson.

I have applied the User Settings in VS Code as the following but still get error:

compileUsingRemoteVersion" : "v0.4.22+commit.4cb486ee.Emscripten.clang",
"solidity.solhintRules": {
"extends": "default",
"rules": {
"avoid-throw": false,
"avoid-suicide": "error",
"avoid-sha3": "warn",
"indent": ["warn", 2]
}
},
"solidity.soliumRules": {
"no-inline-assembly": 5,
"imports-on-top": 0,
"variable-declarations": 0,
"indentation": ["error",2],
"quotes": ["error","double"]
},

Now I've also install Solidity globally in my Linux: $ sudo npm install -g solc Then I've got this from the terminal: /home/userXYZ/.npm-global/bin/solcjs -> /home/userXYZ/.npm-global/lib/node_modules/solc/solcjs + [email protected]

Then changed User Setting: "solidity.compileUsingRemoteVersion" : "latest"

Then re-started VS Code, still I am getting this error... Please help. Thank you

Project / Solution support

There is a need to identify a "solidity" project from others within the same "solution". The extension uses the root workspaces as the project folder due to the lacking of a Solidity project file as standard.

Solution will be to use the original "dapp" file as the project file (or something similar). This will be used as the root of the project and place to look for dependency libraries, either through node, lib or whatever is the configuration.

Resolve node_modules path in compiler

The compiler can't resolve the node_modules path, e.g. as follows:

import "node_modules/zeppelin-solidity/contracts/math/SafeMath.sol";

I have to use the complete relative path to modules, and the vscode-solidity compiler will work:

import "../../node_modules/zeppelin-solidity/contracts/math/SafeMath.sol";

Did i miss something in configuration, or will this be fixed in an future version?

Best regards
Patrice

Adding contract functions in panel [Discussion]

It'd be rad if we could show the contract's functions in a side panel, similar to how the browser compiler Remix does it.

I love being able to code solidity in my own environment so I can use VIM, own syntax highlighting etc... and I think if I could just call functions on my contract directly from vscode then it could be completely stand alone. Thoughts?

Seems to hijack F5 in non-Solidity projects

I have a lot of projects I use VSCode for. Some Solidity/Ethereum, some not. For example if I'm in a Go project and hit F5 to debug it, I get the following warning:

image

It seems your plugin hijacks F5 for all projects even those that have nothing to do with Solidity. The only approach I have is to disable your plugin for every workspace that isn't Solidity-based or going to the debug UI using the mouse. I would suggest finding a way to let VSCode's own task runner compile solidity instead of commandeering a pretty common hotkey.

Support project files (dappfile) as per EIP 82 and project dependencies for compilation

For more info: ethereum/EIPs#82

  • A solidity project will have a project / package file (currently named dappfile) for backwards compatibility with dapple the creators of the EIP82

    • The package file will contain the following information:
    name: dappsys
    version: 0.2.1-dev
    layout:
        sol_sources: contracts
        build_dir: build
    dependencies:
        solidity-stringutils: 1.0.0
    • Dependencies are stored in a common package folder (as per npm-modules) currently named 'dapple_packages' for backwards compatibility with dapple the creators the EIP82.
    • Contracts imports will follow the following format:
        import '../auth/enum.sol';
        import '../auth/events.sol';
        import '../auth/authority.sol';
        import 'solidity-stringsutils/StringUtils.sol';

Where local contracts are referenced using the ./ syntax and dependency packages are referenced using as the prefix the package name.

The ./ syntax is not followed by dapple packages, here it breaks the compatibility as it is a requirement by the compiler, and discussions with the solidity team.

Model Structure:

  • Project class (with ProjectPackage, and Dependencies)
  • Package, containing information from dappfile
  • Introduce Contract, to hold import information to allow resolve from dependencies

Compilation:

A project will be initialised from a default configuration (currently hardcoded) or either dappfile.

Dependencies will be loaded from the file and the recursively from other packages, all the packages are in the same location.

When compiling, dependencies will be identified from imports. Simple pattern are they not local? (not starting with .) and located in the dependency packages.

If found then the same process of finding and resolve imports will be done for that dependency contract.

The compiler should be able to understand a mapping of a "package" together with the local path associated, as it will need to resolve local contract dependencies. This is currently resolved by replacing the import with the absolute path of the package contract.

Syntax error when emitting events in Solidity 0.4.21

This issue is a duplication of this question on Ethereum StackExchange:

I'm having a syntax error in VS Code in the parts where I emit events using new notation for Solidity v0.4.21.

Remix doesn’t raise any errors, though.

My User Settings in VS Code contain "solidity.compileUsingRemoteVersion": "latest", and compiler doesn't raise error on emit itself, rather gives this message:

Syntax error: Expected "!=", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/*", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", ">", ">=", ">>", ">>=", ">>>", "?", "^", "^=", "|", "|=", "||", comment, end of line, or whitespace but "(" found.

Here's how it looks like (2nd emit event is ok for some reason):

screen shot 2018-03-13 at 22 36 25

The problem is in syntax only, compilation completes successfully.

VS Code autocomplete feature broken when extension running

I'm not sure if anyone else has experienced this but autocomplete is working for me in every file type except Solidity. If I disable this extension then autocomplete works properly again with Solidity files. I have set "editor.quickSuggestions": true in my settings but the issue persists. Would be nice to know if others are experiencing this too, it's not great having to double check the spelling every time I reference a variable.

I am running VS code version 1.19.2 on Win 10

where compiled result

When I run 'Compile Current Solidity Contract' command, it response me 'compiled success', but I can't find the results. anyone can tell me where can I find them?

Syntax error when using the new constructor syntax

From solidity v0.4.22 onwards, the new syntax for constructors is:

pragma solidity ^0.4.23;
contract MyContract {
    constructor() public {
        // initialize things
    }
}

The previous version using the contract's name is now deprecated:

pragma solidity ^0.4.23;
contract MyContract {
    function MyContract() public {
        // initialize things
    }
}

On VSCode using this extension, I get the following error when using the new syntax:
ParserError: Expected identifier, got 'LParen' constructor() public { ^.

When compiling my contracts with solc directly or with truffle I get deprecation warnings when using the old syntax, and the new one works well.

Unit testing support

To support unit testing, it will require to integrate internally a testing framework ie dapple or implement a compatible one.

Current investigation:

Integration of dapple (or any other): Most of the frameworks depend on the javascript evm either directly or or indirectly using ethSim, together with many other dependencies, this it will be an impediment for a cross platform environment.

There are two solutions:

  1. Testing framework to use the browserify versions and provide an standalone version, in which compiled tests and code can be pass as a parameter together with the mappings (similar to the solidity compiler).
  2. Create a compatible testing framework which will use the same testing contracts for assertion reporting.

Testing process:

  • Ide identifies test /s to run using the predefined name test pattern.
  • Iterates thorugh each test, compiles it and per test:
  • Pass it as an input parameter with abis to the test runner.
  • Test runner identifies test methods using the predefined name test pattern
  • Test runner creates an evm, deploys the contracts, and executes (calls a transaction) for each one of the tests.
  • Test runner creates a filter, decodes the output, this is returned to the IDE.
  • IDE reports results. If unit tests are ran per test contract (independently) it will be easier to report in the output the specific tests that are failing.

Add Solhint linter against with Solium

Hi Guys!

We developed linter for Solidity that allow to find security vulnerabilities, validate style guide compliance and best practice accordance.

Is it ok - if I implement integration of this plugin to vscode-solidity both with solium. End user it will have possibilities to select needed linter.

What do you think @juanfranblanco?

Thanks!
- Ilya

Warnings on all Functions

No visibility specified. Defaulting to "public" ..... ^ Spanning multiple lines

What is the solution for getting rid of this warning on the functions in my contracts?

How to turn off linting for libraries

Hi,
When I use libraries such as zeppelin, I get annoying linting Warnings for libraries code like this:

linting libraries

Is this possible to turn off linting for imported libraries?

first line pragma flags a compilation error

I start my Solidity with pragma solidity ^0.4.0; and I get an entry in problems tab:

file: 'file:///.../MyContract.sol'
severity: 'Error'
message: '/.../MyContract.sol:1:1: Error: Expected import directive or contract definition.
pragma solidity ^0.4.0;
^'
at: '1,2'

If I comment that first line, I get the following entry in problems tab:

file: 'file:///.../MyContract.sol'
severity: 'Warning'
message: 'pragma-on-top: No PRAGMA directive "pragma solidity <VERSION>" found at the top of file.'
at: '3,1'

So... which way would the plugin be happy? 😄 (obviously the pragma should be there)

JuanBlanco.solidity version: 0.0.31 (right now showing exactly 63,000 downloads, grats!)
solc --version: Version: 0.4.8+commit.60cc1668.Darwin.appleclang
VSCode version: 1.19.3

Compiler Warnings appearing as Errors

Warning messages from the Solidity compiler are appearing as Errors in VS Code. For example, the following code has a "Unititialized storage pointer" warning appearing as an Error in VS Code.

contract TestStruct {

    struct ArrayType {
        int someInt;
        string testString;
    }

    struct SomeStructWithArray {
        int someNumber;
        string someString;
        ArrayType[] someArray;
    }

    SomeStructWithArray[] someStructWithArrays;

    function testAddStruct() {
        // the following gives warning message: "Unititialized storage pointer"
        SomeStructWithArray storage storageSomeStructWithArray;

        storageSomeStructWithArray.someNumber = 123;
        storageSomeStructWithArray.someString = "test";
        storageSomeStructWithArray.someArray.push(ArrayType(123, "test"));

        someStructWithArrays.push(storageSomeStructWithArray);
    }
}

Possible issue compiling after VSCode 1.9.0 upgrade

Hi,
I'm not sure if anyone else is experiencing this issue but following VSCode update to 1.9.0 the following issue appeared when compiling contracts that previously compiled.

There was an error loading the remote version: undefined

image

I fixed this by specifying the following (in user settings)
"solidity.compileUsingRemoteVersion": "v0.4.4+commit.4633f3de"
//v0.4.9+commit.364da425

Again not sure if this is something others are seeing but thought I'd note it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.