Smart contract development proposal #2038
Replies: 1 comment 2 replies
-
Very entertaining read, thank you @adrien-zinger ! 😄 So if I understand correctly:
I agree 100% with the first 2 points. My question lies more into the necessity and redundancy of a low-level
where It mostly boils down to strategy. My vote was to follow Ethereum's design rules (https://eth.wiki/fundamentals/design-rationale):
That's my personal opinion. That being said, I am not an expert in any way and I am open to remarks and feedback :) |
Beta Was this translation helpful? Give feedback.
-
We can be very complex for the development of a smart contract. We can put the high level complexity very hard to understand to have a simple low level execution.
What if massa makes this simple low level and high level both? 🥳
The first way you want to create a smart contract is simple. You have bytecode and you want to store it in the ledger. Let's make a simple zoo:
In this case, there is no initialization needed, it's a very little zoo that doesn't know a lot of animals. Nevertheless you want to open your zoo to the world.
So you compile your code and you get a little_zoo.wasm.
create_sc little_zoo.wasm
288052e20ddd7fdac82efd65015a35d7f5d23bf0
(let's call it little_zoo_addr ok?)More complex zoo
Now your zoo can grow and let the world add any animal. Not safe at all but whatever.
But there is no animal when you open the zoo and that's not a good news for kids 😞 so you have an idea 💡, you want to initialize the smart contract! And you can because the operation CreateSC accept also a constructor bytecode who will be executed with the same context of the executor, and will be able to set datas in the ledger. This constructor look like this:
And now:
world_wild_zoo.wasm
andconstructor.wasm
)create_sc world_wild_zoo.wasm constructor.wasm
Massa will first injects in the ledger your smart contract, and with the context of the smart contract, executes the constructor.wasm, so the constructor has all accesses to modify the smart contract DB and bytecode.
Very simple isn't it?
More complex zoo again
You want to create a zoo that someone can duplicate. In this example, we will just clone the walls of the zoo, and add the animal we want to in there. So you know someone made a private but adaptable zoo called "adaptzoo". It's the same zoo as world_wild_zoo but no one can add a new animal. Instead, he gave access to this function:
This function allow any user to create a new zoo with the same function, obviously this example is very simple. You could create a zoo that allow only specifics users in specific cases to add animals and write a configurable list in the ledger.
So if Matteo want to create a zoo. He can simply write this code:
And then compile it, open his favorite massa client, and send an execution command
exec matteo_zoo.wasm
Hard core level of the zoo
Now, we do know that we can create a zoo (smart contract zoo) with the sugar command
create_sc
, but we can also create a smart contract from another smart contract. You can so create a smart contract that contain another. Look at these line in the adaptzoo.ts:That means that you're not obligated to use the create_sc command to create a smart contract, instead, you can put your smart contract in your constructor and use the command
exec create_sc.wasm
, even if it starting to become unreadable:Beta Was this translation helpful? Give feedback.
All reactions