Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Solidity -> ink! guide #97

Merged
merged 3 commits into from
Oct 25, 2022
Merged

Added Solidity -> ink! guide #97

merged 3 commits into from
Oct 25, 2022

Conversation

peterwht
Copy link
Contributor

@peterwht peterwht commented Oct 6, 2022

Added a guide to convert from Solidity to ink! contracts. This is placed in the ink-vs-solidity page. Original guide can be found here: https://github.com/peterwht/solidity-to-ink-guide.

In Solidity, `require` is used for general (normal) errors -- such as errors that occur based on user input. `require` does have the option for an error string. `revert` is very similar to `require` except that `revert` will be called in `if ... else` chains. Both `require` and `revert` will revert the chain state. In ink!, `if ... { return Err(Error::SomeError) }` should be used for `require` or `revert`. When an `Result::Err` is returned in ink!, then all state is reverted. In general, returning `Result::Err` should be the most used way to return errors.
In Solidity, `require` is used for general (normal) errors -- such as errors that occur based on user input. `require` does have the option for an error string. `revert` is very similar to `require` except that `revert` will be called in `if ... else` chains. Both `require` and `revert` will revert the chain state. In ink!, `if ... { return Err(Error::SomeError) }` should be used for `require` or `revert`. When a `Result::Err` is returned in ink!, then all state is reverted.

In general, `Result::Err` should be used when a _calling contract_ needs to know _why_ a function failed. Otherwise, `assert!` should be used as it has less overhead than a `Result`.
Copy link
Contributor Author

@peterwht peterwht Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the last sentence, "In general, ...", accurate? Based on the discussion here.

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Peter!

@cmichi cmichi merged commit 5d34729 into use-ink:master Oct 25, 2022
AlexD10S added a commit to AlexD10S/ink-docs that referenced this pull request Jan 24, 2023
* Use custom home icon (use-ink#102)

Swizzled the home icon via:

	yarn swizzle @docusaurus/theme-classic Icon/Home --danger

Generated the SVG for the code via:

	npx @svgr/cli <  Breadcrumb.svg

* Added Solidity -> ink! guide (use-ink#97)

* Added Solidity -> ink! guide

* replaced broken links

* Removed no-longer necessary text. Improved some sentence structures.

* Add monthly update for October (use-ink#105)

* Tune text

* Execute `yarn upgrade` (use-ink#106)

* Add link to blog post

* Less text on landing page

* --dev flag implies --tmp (use-ink#107)

* Execute `yarn upgrade`

* Upgrade to docusaurus v2.2.0 (use-ink#108)

* Bump loader-utils from 2.0.3 to 2.0.4 (use-ink#111)

Bumps [loader-utils](https://github.com/webpack/loader-utils) from 2.0.3 to 2.0.4.
- [Release notes](https://github.com/webpack/loader-utils/releases)
- [Changelog](https://github.com/webpack/loader-utils/blob/v2.0.4/CHANGELOG.md)
- [Commits](webpack/loader-utils@v2.0.3...v2.0.4)

---
updated-dependencies:
- dependency-name: loader-utils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add November 2022 Monthly Update (use-ink#113)

* Add November monthly update

* Add Sardinia team photo

* Fill out Sub0 section

* Add photo of fireside chat

* Small fixes for November update (use-ink#114)

* Add Novermber update to sidebar

* Add cropped fireside chat image

* Re-order dependency installation steps (use-ink#117)

* Use openbrush (use-ink#120)

* use openbrush

* add info how to add openbrush to project

* Update openbrush.md

* Improve landingpage (use-ink#123)

* Add and update monthly updates (use-ink#124)

* Add and update monthlies

* Fix broken links

* Adding the structure for support for spanish Documentation (use-ink#104) (use-ink#125)

* config docs in spanish + overview translation

* added support for translating versioning docs

Co-authored-by: Santi Balaguer <santibalaguer@Santis-MacBook-Pro.local>

Co-authored-by: Santi Balaguer <santiago.balaguer@gmail.com>
Co-authored-by: Santi Balaguer <santibalaguer@Santis-MacBook-Pro.local>

* Improve 4.0 landingpage (use-ink#126)

* Update setup.md (use-ink#118)

Use a more recent version that doesn't have strange rpc dependancies as noted here paritytech/substrate#12358

* Update `contracts-node` version everywhere

* Added usage of Enum in basics-storing values page  (use-ink#119)

* add example of string, hash and Enum

* add example of string, hash and Enum

* Update docs/basics/storing-values.md

* Update docs/basics/storing-values.md

Co-authored-by: Michael Müller <mich@elmueller.net>

* Add info about enum storage to versioned page and i18n pages

* Execute `yarn upgrade`

* Support icons in page title

* Improve structure

* Add content for ink! 4.0 + Add ToDo's (use-ink#127)

* Update information on Rococo testnet (use-ink#128)

* Add layout improvements (use-ink#129)

* Use custom info icon

Generated via

	yarn swizzle @docusaurus/theme-classic Admonition -- --wrap

* Update schemas with illustrations

* Add icon for FAQ

* Add FAQ icon

* Make code consistent

* Update ink! vs. Solidity docs

* Fix JSON

* Add more ToDo's for 4.0

* Add more ToDo's for 4.0

* Add documentation of `Environment` trait

* Highlight ToDo annotations

* Explain the `cargo contract new` template (use-ink#131)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Michael Müller <mich@elmueller.net>
Co-authored-by: Peter White <23270067+peterwht@users.noreply.github.com>
Co-authored-by: Squirrel <giles@parity.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Co-authored-by: Dan Quirk <danieljquirk@gmail.com>
Co-authored-by: Dominik | 727 <43150707+coreggon11@users.noreply.github.com>
Co-authored-by: Santi Balaguer <santiago.balaguer@gmail.com>
Co-authored-by: Santi Balaguer <santibalaguer@Santis-MacBook-Pro.local>
Co-authored-by: slmagus <vida.zach@gmail.com>
Co-authored-by: kirti purohit <58950467+Irene-123@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants