Developing smart-contracts with neo-python — what we learned
During one of our hackathons a group of us decided to try out neo-python as the SDK for a simple smart-contract. This is what we learned from that experience.
One operation per line
This one toke us awhile to figure it out, definity _one of those_ things that makes us want to pull out our hair.
Don’t:
current_data = store.deserialize_bytearray(data)
current_data.append(concat(sender, content))
Do:
new_entry = concat(sender, content)
current_data = store.deserialize_bytearray(data)
current_data.append(new_entry)
The interpreter and compiler are still very rudimentary, so “complex” instructions like the former one are still not possible.
Serialization is done only via the utils
We expected to have better support for serialization of data to be inserted in the Storage, but sadly it’s still a work in progress.
Meanwhile we’ve found this handly snippet that does the job just good enough.
No support for complex data structures
This like dict
are not available. The most complex data structure is the list
. Also, be sure to look at the builtins.
Getting the contract invoker hash
Use GetCallingScriptHash
fromboa.blockchain.vm.System.ExecutionEngine
to know the address of the caller/sender.
Resources to keep close by:
- https://github.com/CityOfZion/neo-boa/blob/master/boa/code/builtins.py
to know what can be used in python. remember that only a subset of python is supported - https://github.com/neo-project/docs/blob/master/en-us/sc/tutorial/Parameter.md
neo-python parameters and return types - https://docs.google.com/presentation/d/1b7_gDzkEHHwi8sQI2ulD3rIddxnyNz7S5aHbB3ZXmqs/edit
neo-python workshop - https://github.com/nickfujita/neo-smart-contracts
some sample smart-contract usages on neo-python
Note
This was relevant for the most up-to-date neo-python SDK as of Feb 24th, 2018.
We are aware that development is very much on the way and many things are changing.
We hope this can help anyone hacking away in such preliminary SDKs as we do! It was a bit of a frustrating experience since it limited us a bit on time, but nevertheless we learned a lot from it.
We’re more aware of the current status of the python SDK and how we can contribute to make it more powerful and ease developers life.