Skip to content

Commit 44b4c08

Browse files
committed
readme
1 parent bfa45ea commit 44b4c08

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

compose/contracts/README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Synchronic Web Ontology Compose Network
22

3-
This repository contains materials to deploy a single ontology journal using Docker Compose
3+
This repository contains materials to deploy a single smart contract journal using Docker Compose
44

55
## Requirements
66

@@ -22,3 +22,61 @@ Please set the following environmental variables to configure the notary journal
2222
## End
2323

2424
`$ docker compose down -v`
25+
26+
## Usage
27+
28+
# Account Creation:
29+
In order to use any of the smart contract functions, an account must be created. Create an account using the following call in the interface.
30+
`(*local* "password" (create-account "your_username" "your_password" #f))`
31+
Upon creation, each account will be initialized with a set amount of compute tokens (this number can be set by anyone with the appropriate access).
32+
33+
# Contract Deployment:
34+
To deploy a contract, use the following format. The path to the contract must begin with `*state*`. Contract definitions must be wrapped in a begin statement. Variables must be defined first, as a hash table called vars, with variables initialized to whatever values are necessary. #f can be used as an init value. There is no restriction on function names. When referring to variables in a function definition, refer to them as elements of the hash table, as shown in the below code. Functions can use the caller's username (shown in example ):
35+
```
36+
(*local* "password"
37+
(contract-deploy "your-username" "your-password" (path-to-contract)
38+
(begin (define vars (hash-table 'var-name var-value 'var-name2 var-value2))
39+
(define function-name (lambda (function-parameters) (function-definition)))
40+
)))
41+
```
42+
An example is below:
43+
```
44+
(*local* "password"
45+
(contract-deploy "divya" "passwd" (*state* contracts bill2)
46+
(begin (define vars (hash-table 'votes 0 'voters (hash-table)))
47+
(define vote2 (lambda () (if (eq? (vars 'voters username) #f)
48+
(begin (set! (vars 'voters username) #t) (set! (vars 'votes) (+ 1 (vars 'votes))))
49+
(error "you already voted"))
50+
)))))
51+
```
52+
If a function needs to make a cross-contract call, it can be done as follows, using the cross-call subfunction. In the example below, cross-call is called with three parameters: the path to the contract being called, the index (default #f), and the name of the method in the contract being called. In the example below, the vote-similar method calls the vote2 method, from the contract above.
53+
```
54+
(*local* "password"
55+
(contract-deploy "divya" "passwd" (*state* contracts bill1)
56+
(begin (define vars (hash-table 'votes 0 'voters (hash-table)))
57+
(define vote-similar (lambda () (cross-call '(*state* contracts bill2) #f '(vote2))))
58+
)))
59+
```
60+
61+
# Calling a Contract:
62+
To call a contract, use the format below:
63+
```
64+
(*local* "password"
65+
(contract-call "your-username" "your-password"
66+
(path-to-contract)
67+
#f
68+
(method-name)))
69+
```
70+
71+
Here is an example where a user calls the vote2 method defined above.
72+
```
73+
(*local* "password"
74+
(contract-call "user1" "pass1"
75+
(*state* contracts bill2)
76+
#f
77+
(vote2)))
78+
```
79+
80+
# Compute Tokens:
81+
Deploying and calling contracts require an account because each operation costs an amount of tokens proportional to the number of cpu cycles consumed by the operation. Tokens will be replenished to the starting amount when the replenishment period has passed (the replenishment period can be set by anyone with the appropriate access).
82+

0 commit comments

Comments
 (0)