Deco.Network Alpha Smart Contracts

Deco.Network is a comprehensive blockchain solution for solving issues in software development, specifically open source. Our first product offering is a turnkey solution for dual licensing, which you can read more about here.

We’ve deployed our alpha smart contracts to the Ropsten testnet, and you can interact with them via our website as a dApp. Users can list module licenses for sale, edit those listings, and buy them — all on chain.

But how does it actually work?

There are four main smart contracts to understand: the relay contract, the registry contract, the license sales contract, and the token contract.

The Relay Contract

The relay contract is very simple, and has only one purpose: to hold the official addresses of the registry contract and the license sales contract. This is to provide us with the ability to upgrade the registry and license sales contracts during the development process. That means every time we need to get the registry contract address or license sales contract address, we need to look it up in the relay contract.

The Registry Contract

The registry is where developers can list their modules. You can see the code for the registry smart contract here.

Listing a module

Any developer can list a module using the listModule function:

listModule(uint price, bytes32 sellerUsername, bytes32 moduleName, string usernameAndProjectName, bytes4 licenseId)

Calling this function will create a ModuleForSale struct stored in the registry:

struct ModuleForSale {      
uint price;
bytes32 sellerUsername;
bytes32 moduleName;
address sellerAddress;
bytes4 licenseId;
}

This module for sale is mapped in the “real world” to a specific user and project on our source control instance. That means if you want to see the source code for a given module, you can visit:

https://modules.deco.network/<sellerUsername>/<moduleName>

So for a sellerUsername of “chris” and a moduleName of “react-native-ethereum-wallet”, you can see the source at https://modules.deco.network/chris/react-native-ethereum-wallet

The “price” variable in the struct is the cost of a license for the module in wei. The “sellerAddress” is the ethereum address of the module seller. This is the address where payments will be sent.

Finally, the “licenseId” variable represents the actual software license being purchased. We currently hardcode this to 1 in the alpha, which corresponds to the license listed in our ToS on our website. In the future, we will have a license registry contract that provides a number of license options, and the licenseId field will represent one of those license registry entries.

Editing a module

Developers can also edit a module, in a similar fashion to how they originally listed it using the editModule function:

editModule(uint moduleId, uint price, address sellerAddress, bytes4 licenseId)

Calling this function will change the LicenseForSale struct that is mapped to the moduleId passed in. The seller can change the price of the license, their address where they receive funds, and the license of the module.

The License Sales Contract

The license sales contract keeps track of license sales. You can see the code for the license sales contract here.

Buying a module license

A user can buy a license for a module using the makeSale function:

makeSale(uint moduleId)

Calling this function will create a LicenseSale event in the license sales contract:

event LicenseSale(
bytes32 moduleName,
bytes32 sellerUsername,
address indexed sellerAddress,
address indexed buyerAddress,
uint price,
uint soldAt,
uint rewardedTokens,
uint networkFee,
bytes4 licenseId
);

This event is logged immutably to the ethereum blockchain. This means that the buyer can always easily prove that they bought the license from the developer.

When a user buys a license, a few things happen. First, the LicenseSale event is logged to the blockchain. Next, the seller is rewarded with tokens from the Deconet creator fund. These are test tokens during alpha, and the number of tokens rewarded is stored in the “rewardedTokens” field.

Finally, the module seller is transferred the ETH for the sale. The network takes a small fee, and that amount is logged in the “networkFee” field.

The “soldAt” field holds a timestamp of when the module was sold. And the “licenseId” field holds the licenseId that this sale corresponds to, which will represent an entry in the license registry discussed above.

Conclusion

As you can see, these smart contracts lay the groundwork for the future of software licensing. Using our website, anyone can easily interact with these contracts and start selling software licenses instantly.

Join our community on Telegram to learn more!