3

I am new to Ethereum and I am using visual studio code as an editor for solidity.

I wrote a simple program and save it with .sol extension.

pragma solidity ^0.4.0;

contract SimpleStorage {
   uint storedData;

   function set(uint x) {
       storedData = x;
   }

   function get() constant returns (uint) {
       return storedData;
   }
} 

On Compilation of the current contract (Press F1, Solidity: Compile Current Solidity Contract)

enter image description here

A bin folder with above files is generated after compiling.

Open 'SimpleStorage.json' after compilation from the bin folder. Press F1 and press Solidity: Code generate from compilation output.

enter image description here

A new file with .cs extension a generated as shown above.

I had done up to these steps, What will I have to do for deploying the contract? (Running the solidity contract).

Is there a tutorial for visual studio code solidity extension?

2

To deploy a contract a new transaction is created which will include the bytecode as part of the Data and no address. If you have parameters in the constructor this will need to be encoded correctly and appended at the end.

The are different libraries that simplify the process, depending on the programming language you are using to interact with Ethereum.

1. C# As per the code generated in the question. Just use the function DeployContractAsync. You will have to create a .net project and add Nethereum as a reference using Nuget.

2. Javascript: This is the most common language used to interact with Ethereum, you will need Web3 js, the abi used here can be found on the abi file, and the code is the bytecode.


    web3.eth.contract(abi).new({data: code}, function (err, contract) {
                if(err) {
                    console.error(err);
                    return;
                // callback fires twice, we only want the second call when the   contract is deployed
                } else if(contract.address){
                    myContract = contract;
                    console.log('address: ' + myContract.address);
                    document.getElementById('status').innerText = 'Mined!';
                    document.getElementById('call').style.visibility = 'visible';
                }
            });

3. Java To deploy the contract using Java you can use Web3j, there is a console application which will allow you to create a code generated contract wrapper using the abi and bytecode as an input. Then you should be able to do something as follows:

    YourSmartContract contract = YourSmartContract.deploy(
            , , GAS_PRICE, GAS_LIMIT,
            ,
            , ..., );

4. Truffle: Last but not least, you can install truffle which will take care of the deployment for you using migrations.

1

I didn't try to deploy before using visual studio, but i have seen a demo(devcon1) talking about such thing using BlockApps STRATO.

https://www.youtube.com/watch?v=zf9kB8udWAY

here a tutorial about how to setup your deployement environement using visual studio and blockapps-bloc :

https://blogs.msdn.microsoft.com/caleteet/2016/04/01/solidity-integration-with-visual-studio/

enter image description here

  • Hi, good answer but the question is for vscode not visual studio classic – Juan Blanco Dec 16 '16 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.