The power of a C# SmartContract

Maya Mateva
Strong Force
Published in
3 min readApr 24, 2019

What’s a SmartContract? Easily put, it is programme/protocol for controlling the transfer of assets between parties under some conditions. It has predefined rules and permissions and validates and executes automatically the required actions.

It actually is the mighty idea behind the security and trust in a decentralized system.

Usually, writing a smart contract requires you to deep dive into a whole new ecosystem — solidity, truffle, ganache, etc. — an ecosystem being a work in progress (of course, like everything else in an IT world) with a lot of new opportunities for improvements as well as flaws (or more appropriately said, not yet developed). Unsurprisingly, it might be a bit overwhelming, right? But what if you could sail into the ocean of smart contracts with a boat you already know how to run? What if you could use a weapon as strong as C# for that?

It would be great, ah? Yes. And it would be possible with StrongForce — a Smart Contracts framework built on Tendermint consensus (check out the Hello, World of StrongForce).

What is a StrongForce Contract?

StrongForce exposes dotnet core-based smart contracts that enable you to easily create your own contracts and plug them in the system. The main idea of the contract is to be easily and uniquely identified (by its Address), handle Actions that have been sent to it (with the virtual method Receive (Action action)) and forward the action in a case that particular contract does not have permissions to execute it (with the virtual method Redirect(Action action)). Once some of the prerequisites are met, a corresponding event Send or Forward is thrown.

public abstract class Contract{    protected Contract(Address address)
{
this.Address = address; }
public Address Address { get; }
internal event EventHandler<ActionEventArgs> Send; internal event EventHandler<ActionEventArgs> Forward; protected internal abstract object GetState(); protected internal virtual bool Receive(Action action) { return this.HandleReceivedAction(action);
}
protected abstract bool HandleReceivedAction(Action action); protected virtual void Redirect(Action action) { }
}

The forwarding is executed by shooting a bullet (a metaphor we are using for finding the next Contract that has permissions to ‘take the bullet’). Stay tuned for a more deeply explanation on that idea we developed in StrongForce.

And that’s it. Once a contract is initialized, the ContractRegistry will take care of it — register it, make sure it’s unique and place it in the path for searching the next element in the tree that can handle a particular action.

The abstract class Contract can be easily extended and modified to meet particular requirements and of course, even the custom ones will be handled by the ContractRegistry. Thus, you can create your own hierarchy of smart contracts, defines the permissions required by each of them and then controls the execution of an action. The forwarding will come out-of-the-box thanks to the logic inside StrongForce.

So, all you need to do is sketch the tree of smart contracts that you need, extend the Contract class and set the permissions each of them has. And that’s it. You are good to go to create a powerful system that will handle the execution of the logic of a contract on the chain.

Happy coding + smart-contract-ing ❤

--

--