I understand from https://stellar.stackexchange.com/questions/92/is-something-like-smart-contracts-possible-in-stellar that there is no built-in way to do so, however maybe there is some kind of an integration platform for doing so that is commonly used. What would you recommend?
4 Answers
A workflow you'd want to study is the Compliance/AML setup and docs. https://www.stellar.org/developers/guides/compliance-protocol.html
It uses a "Bridge Server" to implement WebHooks which control the transaction workflow. https://www.stellar.org/developers/guides/anchor/2-bridge-server.html
The pattern could also generate transactions as a consequence what it sees. And it's how/where I see you would also get the equivalent of ETH Oracles functionality (data requested from the outside world) into your workflow's code.
I know "Compliance" sounds complicated and doesn't sound at all like a Smart Contract, but it's comparatively simple, it implements "tests" and "rules" to "allow/disallow" transactions, it requests more information if the transaction is "incomplete". "Compliance" in an abstract sense is a smart contract.
The "transaction attachment" used to carry the AML data could just as easily be used to carry function call meta data parameters instead (Careful though because as I understand it, the attachments aren't recorded in the ledger and are "temporary").
https://www.stellar.org/developers/guides/attachment.html
The pre-authorized transactions and multisignature concepts can be used to create trustable "transactional conversations" between the parties working with a "shared account" (what I call the "escrow account" or in this case the "contract account").
Lastly, I've also been examining the potential of using trustline limits for attributing an asset qty to other Stellar accounts (You use the same asset_code (asset_code of your choice) on all records and set the remote account as the issuer. The remote account never has to send any of the asset, the trustline limit amount itself is marking the qty on the "contract").
This would be like the ETH model where a contract's data is kept local to the contract. Since your code can completely control the trustline limits on its own account, your code completely controls the qty ascribed to those "issuer" accounts.
Caveat that nothing else in the Stellar Universe would view those amounts that way, but if it worked as a pattern things could later be taught. My expectation is by introducing a new "Account Type" that worked this way. Something I've been calling an "'Asset' Account Type" which behaves differently than the existing "'Currency Balances' Account Type".
My thinking is that eventually "account type" evolves into some kind of "Contract Id" for the system and the existing Stellar Accounts (all of type 1) then become Accounts on the '1' Contract Code.
Obviously almost none of that has been written yet, but it should give you some "directions" to explore.
Mike
AFAIK There are two ways where to create smart contracts
- programmatically - by using one of Stellar SDKs
- web interface - Stellar Laboratory
As to how to create smart contracts, you may be interested to read about these building blocks:
- Account multisignature
- Transaction pre-authorizing (also, publishing it publicly)
- Transaction pre-signing (also, privately giving that to other party)
- Transaction authorization with hash (also for atomic cross-chain swaps)
- Transaction time bounds
- Transaction sequence number
- "Worker accounts" (also, for parallelizing lots of transactions)
- Offers of own tokens (i.e. crowdfunding tokens)
- ... I have a feeling that there are few more but can't remember
'Smart Contracts' in Stellar are handled by the use of the Multisignature concept. You just need to keep in mind that they are not Turing Complete as the smart contracts in Ethereum.
Stellar uses a number of core concepts and primitives that can be used by contract designers to build robust systems.
These include:
- atomic batches of operations (transactions)
- multiple signers per account
- the ability to assign different weights to different signers
- the ability to set weight thresholds for operations
- the ability to sign transactions offline without submitting them
- validity date ranges on transactions.
- the fact that participants in a transaction will almost always use what they have/know for their own benefit.
With these building blocks, it is possible to design complex business interactions. The platform is pen and paper, I guess. Or a whiteboard. The transactions themselves can be constructed using any of the numerous SDKs, or the Stellar laboratory.
It would be great to have a cookbook of Stellar contract "recipes". In lieu of that, we can turn to schemes documented by some of our esteemed community members, such as this simple example by Jed himself of Joint Crowdfunding.