4

I enjoy writing custom pallets so I would like to know if instead of writing an ink! smart contract and then compiling it to .wasm and deploying it to the Contracts module/pallet of a Substrate-based chain, would it be possible to instead write the same logic in a custom pallet and then compile that to .wasm, and then deploy it to the Contracts pallet/module of a Substrate-based chain?

1
  • there is currently a sol2ink repository to convert Solidity to ink! github.com/Supercolony-net/sol2ink. so maybe one option could be to create a similar pallet2ink repository to allow for easy migration from a custom pallet to an ink! smart contract that could then be compiled to .wasm and deployed to the Contracts module/pallet of a Substrate-based chain. Jun 20 at 12:52

1 Answer 1

1

From the ink! docs:

ink! is just standard Rust in a well defined "contract format" with specialized #[ink(…)] attribute macros. These attribute macros tell ink! what the different parts of your Rust smart contract represent, and ultimately allow ink! to do all the magic needed to create Substrate compatible Wasm bytecode!

In my opinion is a very interesting question, I hope to see some good ideas answering your question. Here is mine:

As far as I know there is not a direct way to do that, as Luke suggested in the comment one option would be to create a tool that translate the pallet runtime code into the ink! code, and then we will be able to generate a Wasm binary, a metadata file (which contains the contract's ABI) and a .contract file which bundles both.

A few months ago I did that exercise manually, I built a pallet and I convert it into a smart contract in ink!. I was able to reuse most of the code and replace the FRAME Macros with the ink! macros was not a big deal. However I found a couple of stoppers where the translation was not that trivial:

So keep in mind that some of the things that you can do on pallets will need a very special treatment using ink!, and example might be interacting with other pallets in the runtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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