In a decentralized environment, there is no way to verify whether the information held by a node is up-to-date or not.
Therefore, it is recommended to set multiple endpoints.
For practical code examples, please refer to the example files in SASEUL JS Github.
Quick Start (Exploring Block data)
Set the endpoint, then inquire the round information, and request the block information that meets the conditions.
Refer to the System Method section for the methods you can use as a default.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SASEUL.Rpc.endpoints(["<ENDPOINT1>", "<ENDPOINT2>", "<ENDPOINT3>", ...]);
SASEUL.Rpc.bestRound().then(results => {
let obj = SASEUL.Rpc.simpleRequest({ type: "ListBlock", page: 1, count: 5 });
let condition = (blocks) => {
let latest = Object.values(blocks).reduce((prev, curr) => curr.height > prev.height ? curr : prev);
return latest.height >= results.main.height;
}
SASEUL.Rpc.raceRequest(obj, condition).then(function (r) {
console.dir(r);
});
});
// result:
{
"code": 200,
"data": {
// BLOCK DATAS
...
}
}
Checking Balance and Transfer
The SASEUL Main Network essentially provides functions related to cryptocurrency.
This currency is expressed as SL
, and SL
is used as a fee when sending a Transaction or registering and changing a Contract in the network.
For Methods related to SL, please refer to the Method list of Explorer - Contracts.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
SASEUL.Rpc.endpoints(["<ENDPOINT1>", "<ENDPOINT2>", "<ENDPOINT3>", ...]);
let private_key = "<YOUR_PRIVATE_KEY>";
let public_key = SASEUL.Sign.publicKey(private_key);
let from_address = SASEUL.Sign.address(public_key);
let to_address = "<TO_ADDRESS>";
let amount = "<AMOUNT>"; // number
// Get Balance
let obj = SASEUL.Rpc.simpleRequest({ type: "GetBalance", address: from_address });
SASEUL.Rpc.raceRequest(obj).then(function (r) {
console.dir(r); // check SL balance
});
// Send SL
obj = SASEUL.Rpc.signedTransaction({ type : "Send", to: to_address, amount: amount}, private_key);
SASEUL.Rpc.broadcastTransaction(obj).then(function (r) { console.dir(r); });
Checking Mined Resources and Refining
The SASEUL Main Network stores the contribution to block creation in the form of Resource
.
Resource
can be refined into SL
using a “Refine” contract.
For related methods, refer to the System Method section and the Method list from Explorer - Contracts.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SASEUL.Rpc.endpoints(["<ENDPOINT1>", "<ENDPOINT2>", "<ENDPOINT3>", ...]);
let private_key = "<YOUR_PRIVATE_KEY>";
let public_key = SASEUL.Sign.publicKey(private_key);
let address = SASEUL.Sign.address(public_key);
// Get Resource
let obj = SASEUL.Rpc.simpleRequest({ type: "GetResource", address: address });
SASEUL.Rpc.raceRequest(obj).then(function (r) {
console.dir(r); // Check resource amount
});
// Refine
obj = SASEUL.Rpc.signedTransaction({ type : "Refine", amount: "<REFINE_AMOUNT>"}, private_key);
SASEUL.Rpc.broadcastTransaction(obj).then(function (r) { console.dir(r); });
Writing and Deploying Smart Contracts
On the SASEUL Main Network, anyone can deploy a Smart Contract as long as they have SL
.
Since functions related to the Smart Contract do not work in a browser environment, use the functions in a Node.js environment.
The test network endpoint for testing is test.saseul.net. [(Testnet Explorer)(https://explorer.saseul.com/test-net.html?ic=tx&ia=list)]
For detailed Contract syntax, refer to the Smart Contract section and the code in Sample Contract Github.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const SASEUL = require('saseul');
let op = SASEUL.SmartContract.Operator;
function mint(writer, space) {
let condition, err_msg, update;
let method = new SASEUL.SmartContract.Method({
"type": "contract",
"name": "Mint",
"version": "1",
"space": space,
"writer": writer,
});
method.addParameter({"name": "name", "type": "string", "maxlength": 80, "requirements": true});
method.addParameter({"name": "symbol", "type": "string", "maxlength": 20, "requirements": true});
method.addParameter({"name": "amount", "type": "string", "maxlength": 80, "requirements": true});
method.addParameter({"name": "decimal", "type": "int", "maxlength": 2, "requirements": true});
let from = op.load_param('from');
let name = op.load_param('name');
let symbol = op.load_param('symbol');
let amount = op.load_param('amount');
let decimal = op.load_param('decimal');
let info = op.read_universal('info', '00');
// info === null
condition = op.eq(info, null);
err_msg = 'The token can only be issued once.';
method.addExecution(op.condition(condition, err_msg));
// writer === from
condition = op.eq(writer, from);
err_msg = 'You are not the contract writer.';
method.addExecution(op.condition(condition, err_msg));
// amount > 0
condition = op.gt(amount, '0');
err_msg = 'The amount must be greater than 0.';
method.addExecution(op.condition(condition, err_msg));
// decimal >= 0
condition = op.gte(decimal, '0');
err_msg = 'The decimal must be greater than or equal to 0.';
method.addExecution(op.condition(condition, err_msg));
// save info
update = op.write_universal('info', '00', {
"name": name,
"symbol": symbol,
"total_supply": amount,
"decimal": decimal,
});
method.addExecution(update);
// from balance = amount;
update = op.write_universal('balance', from, amount);
method.addExecution(update);
return method;
}
let private_key = "<YOUR_PRIVATE_KEY>";
let public_key = SASEUL.Sign.publicKey(private_key);
let address = SASEUL.Sign.address(public_key);
let space = "<SPACE_NAME>";
SASEUL.Rpc.endpoints(["<ENDPOINT1>", "<ENDPOINT2>", "<ENDPOINT3>", ...]);
let contract = new SASEUL.SmartContract.Contract(address, space);
contract.addMethod(mint(address, space));
contract.publish(private_key);