Skip to content

Managing Smart Contracts

Wouter den Bakker edited this page Nov 29, 2019 · 1 revision

It is properly easiest to use https://coinversable.github.io/validana-client/ to add/delete smart contracts. Connect to your Validana Server with the right prefix, enter your private key, use the 'Create Contract' or 'Delete Contract' contract and fill in all fields. Where needed the fields will automatically base64 encode the data and replace the contract name with the hash. Send the transaction and the contract will be created/deleted. If you wish to create/delete smart contracts yourself see below.

Adding smart contracts

Adding a smart contract is the same as calling any other transaction. The main difference is that it is no real contract, so it can not be retrieved by requesting all contracts from the server. If using the Validana Client this means having to use the signAndSend() method instead of the processTx() method. The hash of the 'Create Contract' contract is all 64 zeros (as hex). The code/init contents should be base64 encoded. The template for creating a smart contracts is:

{
	"type":{"type":"string","desc":"The name of the contract.","name":"Name"},
	"version":{"type":"string","desc":"The version of the contract.","name":"Version"},
	"description":{"type":"string","desc":"A description of the contract.","name":"Description"},
	"template":{"type":"json","desc":"The template the contract should follow.","name":"Template"},
	"init":{"type":"base64","desc":"The code to be executed when the contract is created.","name":"Init"},
	"code":{"type":"base64","desc":"The code to be executed when a transaction uses this smart contract.","name":"Code"},
	"validanaVersion":{"type":"uint?","desc":"The version of Validana for which this contract is created.","name":"Validana Version"}
}

This results in having to call the contract with (for example):

{
	"type": "mycontract",
	"version": "1.0",
	"description": "This is my contract",
	"template": {},
	"init": "abcdefg=",
	"code": "abcdefg=",
	"validanaVersion": 2
}

Deleting smart contracts

Deleting a smart contract is similar to creating a smart contract. The hash of the 'Delete Contract' contract is 64 Fs (as hex). The hash of the contract to delete should be hex encoded. The template for deleting a smart contracts is:

{
	"hash":{"type":"hash","desc":"Delete a smart contract.","name":"Smart Contract"}
}

This results in having to call the contract with (for example):

{
	"hash": "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
}

Clone this wiki locally