You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRACT.md
+42-23Lines changed: 42 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -85,17 +85,40 @@ Before we dig in, we need to know that a contract's storage is a key-value objec
85
85
86
86
Arguments can be represented as `%0`, `%1`, `%2`,..., `%n`.
87
87
88
-
### Utils
88
+
### Block data
89
89
90
-
* Print out a value: `log value`.
91
-
* Store contract's balance into a variable: `balance var_name`.
92
90
* Store block's timestamp into a variable: `timestamp var_name`.
93
-
* Store sender's address into a variable: `address var_name`.
91
+
* Store block's number into a variable: `blocknumber var_name`.
92
+
* Store block's hash into a variable: `blockhash var_name`.
94
93
* Store block's difficulty into a variable: `difficulty var_name`.
95
94
95
+
### Transaction data
96
+
97
+
* Store transaction's amount into a variable: `txvalue var_name`.
98
+
* Store transaction's sender address into a variable: `txsender var_name`.
99
+
* Store transaction's gas into a variable: `txgas var_name`.
100
+
* Store transaction's contract execution gas into a variable: `txexecgas var_name`.
101
+
102
+
### Contract data
103
+
104
+
* Store contract's address into a variable: `address var_name`.
105
+
* Store contract's balance into a variable: `selfbalance var_name`.
106
+
107
+
### Chain interactions
108
+
109
+
* Store address's balance into a variable: `balance var_name, address`.
110
+
* Send Jem to an address: `send address, amount`.
111
+
112
+
### Others
113
+
114
+
* Print out a value: `log value`.
115
+
* Generate SHA256 hash of a value and store into a variable: `sha256 var_name, value`.
116
+
* Store remaining gas into a variable: `gas var_name`.
117
+
* Stop execution: `stop`. (will not cost gas)
118
+
96
119
## Deploying a contract
97
120
98
-
A contract is attached to a transaction when deployed, so to deploy a contract, simply create a transaction, paste the contract's code into the `to` property, put `SC` at the beginning of the code to show that this is a smart contract's code and send the transaction away.
121
+
A contract is attached to a transaction when deployed, so to deploy a contract, simply create a transaction, paste the contract's code into `<tx>.additionalData.scBody`, and then broadcast the transaction away.
If the gas provided in the transaction is not greater or equal to the gas calculated, the contract will not be triggered.
140
-
141
-
Note: This is not your transaction's gas fee, it is for paying the contract's fee, so you should be passing it into the transaction constructor as `amount`.
160
+
Note that all args should be strings and are then stringified.
Copy file name to clipboardExpand all lines: README.md
+21-73Lines changed: 21 additions & 73 deletions
Original file line number
Diff line number
Diff line change
@@ -47,87 +47,39 @@ node keygen.js
47
47
48
48
And it will generate a public key and a private key for you.
49
49
50
-
### Sync chain
51
-
52
-
Currently, an "agreed" JeChain chain hasn't existed yet, so you can either create a new chain by skipping this whole section, or sync a chain from someone you happen to know that runs a JeChain node using `requestChain`.
50
+
### Configure your node
53
51
54
-
In `./src/jenode.js`, at the bottom of the file, add:
52
+
In `config.json`, change the props for your needs:
55
53
56
54
```js
57
-
requestChain("Some JeChain node address");
55
+
{
56
+
"PORT":/*PORT that your node will run on, default is 3000*/,
57
+
"RPC_PORT":/*PORT that the RPC server will run on, default is 5000*/,
58
+
"PEERS":/*An array containing peers' address that the node will connect with, default is an empty array*/,
59
+
"MY_ADDRESS":/*A string containing the node's address, default is "localhost:3000"*/,
60
+
"PRIVATE_KEY":/*A string containing a private key*/,
61
+
"ENABLE_MINING":/*Leave true if you want to mine, default is false*/
62
+
"ENABLE_LOGGING":/*Leave true if you want to log out contract logs, default is false*/,
63
+
"ENABLE_RPC":/*Leave true if you want to run a RPC server, default is false*/,
64
+
"SYNC_FROM":/*A string containing an address to sync chain from*/,
65
+
"ENABLE_CHAIN_REQUEST":/*Leave true if you want to sync chain from others, default is false*/
66
+
}
58
67
```
59
68
60
-
### Configure your node
61
-
62
-
In the terminal, follow this template:
69
+
To see an example, `config.json` already has some data set for you to have a look at.
63
70
64
-
```sh
65
-
# PORT=Server's port (e.g: 3000) (default is 3000)
66
-
# PEERS=Addresses to connect to (e.g: ws://localhost:3001, ws://localhost:3002, ws://localhost:3003) (default is blank)
67
-
# MY_ADDRESS=Server's address: ws://your.ip.and:port (e.g: ws://192.168.100.2:3004) (default is ws://localhost:3000)
68
-
# PRIVATE_KEY=Your private key (default is a new randomly generated key)
69
-
# ENABLE_MINING=true if you want to mine, skip otherwise (default is blank)
70
-
# ENABLE_LOGGING=true if you want to log out contract messages, skip otherwise (default is blank)
71
+
### Running the node
71
72
72
-
# ENABLE_RPC=true if you want to run an RPC server, skip otherwise (default is blank)
73
-
# RPC_PORT=RPC server's port (e.g: 5000) (default is 5000)
74
-
75
-
# Start the node
76
-
node .
77
-
```
78
-
79
-
Use `set` on Windows to set variables.
73
+
After everything is all set, simply type `node .` to run the node.
80
74
81
75
### Interacting with the node through JSON-RPC apis
82
76
83
-
(This will require you to run an RPC server).
84
-
85
-
To properly interact with the node, you should use the JSON-RPC apis, especially if you are creating dapps.
77
+
This process will need you to run an RPC server, basically leave `true` in `ENABLE_RPC` in `config.json` to enable it.
86
78
87
-
[Check out docs for JSON-RPC APIs here.](./JSON-RPC.md)
79
+
To properly interact with the node, you should use the JSON-RPC apis, especially if you are creating dapps. To get started, check out [docs for JSON-RPC APIs here.](./JSON-RPC.md)
88
80
89
81
**Note: This feature is still in its early stages, things might change when a stable release is ready.**
90
82
91
-
### Using the node manually through code:
92
-
93
-
You can also just use manual functions in `./src/jenode.js`
94
-
95
-
Mine a block:
96
-
```js
97
-
mine();
98
-
```
99
-
100
-
Broadcast a transaction:
101
-
```js
102
-
sendTransaction(yourTransactionObject);
103
-
```
104
-
105
-
To create a transaction object, use `Transaction`:
106
-
107
-
```js
108
-
consttx=newTransaction(publicKey, "address to be sent to", amount, gas, [args_optional]);
109
-
110
-
// Sign the transaction
111
-
tx.sign(keyPair);
112
-
```
113
-
114
-
Request for a chain and its information from some address:
115
-
```js
116
-
requestChain("Some JeChain node address");
117
-
```
118
-
119
-
If you just want to set up a node that mines continuously (like most people would), use `loopMine`:
120
-
```js
121
-
loopMine(optionalDelayTime);
122
-
```
123
-
124
-
Note: `loopMine` is used by default when mining is enabled.
125
-
126
-
You can manually connect to a node using `connect`:
127
-
```js
128
-
connect("Some JeChain node address");
129
-
```
130
-
131
83
### Run JeChain node publicly
132
84
133
85
Just do some port-forwarding, drop your public IP + the port you forwarded in and you are set!
@@ -163,15 +115,11 @@ Note that this is an experimental project which is still under development, and
163
115
164
116
## Todos
165
117
118
+
* Fix bugs.
119
+
* Update chain sync.
166
120
* Implement a proof of stake protocol.
167
121
* Implement sharding.
168
122
* Integrate EVM into the chain?
169
-
* Use a proper database (preferably LevelDB).
170
-
* Refactor codes, or rewrite in another language entirely, preferably Rust.
171
-
* Port websocket to other p2p protocols.
172
-
* Update missing documentation.
173
-
174
-
Full todo list can be seen here: https://github.com/nguyenphuminh/JeChain/projects/2
0 commit comments