Using Eclipse IDE for EOS smart-contracts

3년 전

Recently we've been trying to find an efficient method to work with EOS smart-contracts. For two reasons. Firstly, we wanted to be able to thoroughly examine the way the examples supplied by EOS developers are constructed. Secondly, we wanted to have a tool which will allow us to play with our own attempts at creating smart-contracts.

Not smart enough

Working with complex code in a plain text editor is not an option for us. We are not smart enough to deal with complex smart-contracts without extra help.

We needed a tool which understands the structure of the code, so it can present it to us in all different aspects and show us all the intricate relationships inside the code. Also, we needed a tool which will point out errors and produce warnings in our newly created code, so that we can spot and fix them before attempting to send it to the WebAssembly compiler.

In other words, what we needed was an IDE (Integrated Development Environment).

Here comes Eclipse

And after several attempts with various tools we've discovered that Eclipse CDT (C/C++ Development Tooling) can do the job quite well.

eclipse.png

Importing EOS smart-contracts into Eclipse is a trivial task. It just worked without any extra efforts on our part. It turns out Eclipse code indexer engine is smart enough to correctly parse the latest C++14 standard which is being used by EOS devs.

As expected, in Eclipse the demo smart-contracts have become much clearer.

We could see the entire structure of the code:
02q.png

We could select any method and see all its references:
03q.png

We could see the entire call hierarchy of a given method:
04q.png

And last but not least, when working with a new code we could utilize the powerful refactoring tools offered by Eclipse.

How to do it?

  1. Firstly, you need to create a copy of EOS repository on your computer:
    git clone https://github.com/eosio/eos --recursive

  2. Then you need to make sure you have Java 8 or 9 installed:
    java -version
    If not, you can get it here.

  3. And finally you need to download Eclipse CDT, which is a special edition dedicated to C++ development.

Where are the demo contracts?

Inside the repository, demo smart-contracts are located in the contracts folder. There are several of them, here is a list of those which do work:

  • currency
  • exchange
  • infinite
  • proxy
  • simpledb
  • storage

Additionally you will need the header files contained in the contracts/eoslib folder. Demo contracts are dependent on them.

Use symbolic links

In order not to mess up your local EOS repository with Eclipse workspace files, we suggest creating Eclipse workspace outside the repository and then using symbolic links. This way you can easily make sure the demo contracts are always up to date by running git pull --recursive, while you can keep the Eclipse stuff outside of the repository.

To create a symbolic link you need to execute this command:
-- on Windows: mklink /D path-to-destination-folder path-to-source-folder
-- on Ubuntu: ln -s path-to-source-folder path-to-destination-folder

Replace path-to-source-folder with the path to a smart-contract example in your EOS repository, and path-to-destination-folder with a path to a smart-contract example in your Eclipse workspace.

You need to run a separate command like this for every demo contract. For example this command creates a symbolic link for the currency demo contract:

mklink /D X:\Workspaces\EOS\WebAssembly\Contracts\src\currency X:\Workspaces\EOS\eos\contracts\currency

Can we achieve more?

Switching to Eclipse was a big improvement for us but we wondered if we could push it one step further - compile the code right inside Eclipse, so that we have the code additionally verified by a C++ compiler. The reason we would want this is that the code indexer is only able to discover syntactic errors (as well as discover syntactic errors (as well as some semantic onones), while the compiler would offer us the ultimate verification: everything except run-time errors.

As EOS is using the experimental C++14 standard, setting up a C++ compiler capable of this task is quite tricky. We will describe it in a separate post. So stay tuned for more on this subject.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
STEEMKR.COM IS SPONSORED BY
ADVERTISEMENT
Sort Order:  trending
  ·  3년 전

the code indexer is only able to spot semantic errors

You meant syntactic, right?

·

Thanks for pointing it out.

Technically you are right - at least according to the formal definition.

Eclipse seems to present all errors discovered by the indexer as semantic - hence the mistake.
synctatic.png

I've corrected the text to reflect that the code indexer can discover syntactic errors as well as some semantic ones (e.g. nonexistent variables).

  ·  3년 전

the code indexer is only able to spot semantic errors

You meant syntactic, right?

·

Very interesting, good post and I like, hopefully the next post better with a more perfect idea. follow me @pojan, Upvote and give a positive comment for me.

https://steemit.com/introduceyourself/@pojan/at-the-gate-of-this-steemit-place-we-incised-the-decree-above-the-throne-crowned-pearly-grains-of-pearls-we-reign-on-each

Working with complex code in a plain text editor is not an option for me either :)
Your extra help is very welcome!
Thank you very much for taking the time to share your knowledge.

can eos support java language ?

  ·  3년 전

Keep on informing. Very nice for the community.

Thanks @tokenika for your post, your invention is so beneficial ...! We will keep waiting for further discoveries

this is cool :)

great info keep it up

This post has received a 100.00 % upvote from @steemdiffuser thanks to: @jbbasics. Steem on my friend!

Get Upvotes, Join Our Trail, or Delegate Some SP

·

Hello & Cheers!! I'm a content detection and information bot. You are receiving this reply because a short link or links have been detected in your post/comment. The purpose of this message is to inform your readers and yourself about the use of and dangers of short links.

To the readers of the post: Short links are provided by url shortening services. The short links they provide can be useful in some cases. Generally their use is benign. But as with all useful tools there are dangers. Short links can be used to hide all sorts of things. Quite frequently they are used to hide referral links for instance. While not dangerous this can be deceptive. They can also be used to hide dangerous links such as links to phishing sites, sites loaded with malware, scam sites, etc. You should always be extremely cautious before clicking on one. If you don't know and trust the poster don't click. Even if you do you should still be cautious and wary of any site you are sent to. It's always better to visit the site directly and not through a short link.

To the author of the post: While short links may be useful on some sites they are not needed on steemit. You can use markdown to format your links such as this link to steemit. It's as simple as [steemit](https://steemit.com) Unlike short links this allows the reader to see where they are going by simply hovering over the link before they click on it.

This message was created by a bot. It is part of the ongoing fight against spam and phishing attacks on steemit. If you did not use short links in your post and feel you have received this message in error you can contact @fubar-bdhr on discord or @fubar.bdhr on steemit chat to report the issue.

Will it wokr in future in microsoft visual studio?

sth_ron.PNG

What am I doing wrong?
Can somebody help me with making proper import to this IDE?

Very helpful. thank you

I have a setup for working with EOS contracts in the CLion IDE here outlined here:

https://steemit.com/eos/@ukarlsson/eos-contracts-development-with-the-clion-ide

It can also build the wast and abi files directly in the IDE.