XSN Technical Documentation | Trustless Proof of Stake Contracts

Hydranet Team
Stakenet
Published in
3 min readApr 23, 2018

Purpose

This feature was created with the intention of allowing users to safely and securely stake XSN coins in cold storage from hardware devices. Increasing security for both the network (as more coins will stake on a TPoS vs non) and the user. This feature required a hard fork to implement on our existing chain (PoSW) — Our new chain (XSN) has been launched for a month with over 30k+ TPoS blocks successfully minted, and a thriving marketplace of merchants has arisen providing the service of safely staking XSN for our users.

TPoS Contract

A XSN Trustless Proof of Stake (TPoS) contract is a special agreement made on our blockchain which allows an owner of a given address (we call “owner”) the ability to give staking permission to a separate address (we call “merchant”) — the owner of this merchant address does not have permission to move funds in the tpos address, only the right to stake the balance of that address. The owner can move his funds out of the TPoS address at any and all times, giving him complete control of his funds during and throughout the execution of this contract.

Required information to create a TPoS contract

The contract is a special transaction with OP_RETURN that holds data specifying the terms. The contract is created by a user sending 1 XSN to himself — this transaction will also broadcast the terms of the contract to the network. This 1 XSN needs to be made lowest priority when user spends XSN from his Ledger wallet (if the 1 XSN is spent it will break the contract)

To cancel the TPoS contract the user simply needs to move all of his funds into a new address.

Required information in the contract are as follows:

1. tposAddress — Address owned by creator of contract (this balance will stake via TPoS)

2. merchantAddress — owner of this address will have the ability to stake the balance in ‘tpos address’

3. commission (value between 1–99%) — tells the protocol how to split staking rewards minted from tpos address (allowing owner to auto pay commission to merchants)

4. signature — signature by creator of the contract showing proof that he is the owner of the tpos address

Sample contract:

out 0: { tposaddress : 1 XSN} (deposit)
out 1: { OP_RETURN XoX31nLRYeteYLHMibYmHALCV7bE2PPRH6 Xp944knpdSSWex2uH2he5CKZg2sN12bbPS 10 65_bytes_signature }
out2: { changeaddress: changeamount }

RPC CALLS

We have created RPC calls to create a TPoS contract and submit it to the network:

RPC call 1 tposcontract create [tpos_address] [merchant_address] [comission] — this call will return a hex encoded contract, which can be sent to the network using RPC call 2

RPC call 2 sendrawtransaction [hex encoded contract]

snapshot of a contract being created and broadcasted on our network via RPC

snapshot of a contract being created and broadcasted on our network via RPC

Sample “one click” TPoS UI:

In the image below there is an example of a “One click TPoS” UI taken from the XSN desktop wallet

Once the user fills the required fields and clicks “stake” the backend executes 4 steps

1) Generates new address(the tpos address)
2) Generates contract using: result from step 1, merchantAddress and commission (values inputted by user)
3) broadcasts contract to the network
4) Send XSN to the tpos address created in step 1 (amount inputted by user in UI)

Sample proof of concept for TPoS UI — — User fills 3 values and clicks ‘stake’

--

--