1.6.0 • Published 2 years ago

saseul-js-cli v1.6.0

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
2 years ago

SaseulJS CLI - SASEUL NodeJS Command Line Interface

NPM Version

NPM Install Size

NPM Downloads

Getting Started

NodeJS Command Line Interface for SASEUL blockchain.

Installing SaseulJS CLI

You can install like below.

npm install saseul-js-cli -g

saseul-cmd

init

Initiates SaseulJS CLI. The private key will be encrypted and stored in rpc-env.json and the network will be added to the config.env.

saseul-cmd init

set password: {your password}
network_name: {your SASEUL network_name} # example: SASEUL PUBLIC NETWORK
system_nonce: {your saseul system_nonce} # example: Fiat lux.
default_peers: {your saseul defalut_peers} # example: ["127.0.0.1", "123.123.123.123", ...]
private_key: {your private key || generate a random key}
abi_option: {your abi_option object}

reset

Reset all or selected init variables.

saseul-cmd reset {key}

password: {your password}
network_name: {your SASEUL network_name} # example: SASEUL PUBLIC NETWORK
system_nonce: {your saseul system_nonce} # example: Fiat lux.
default_peers: {your saseul defalut_peers} # example: ["127.0.0.1", "123.123.123.123", ...]
private_key: {your private key || generate a random key}
abi_option: {your abi_option object}

login

saseul-cmd login

password: {your password}

logout

saseul-cmd logout

get-env

Get init variables.

saseul-cmd get-env

create

Generates SASEUL smart contract code from template. You can edit the generated Javascript file to proceed.

saseul-cmd create {contract or request or method} {name} {space} {version}

compile

Compiles the created Javascript file into JSON format.

saseul-cmd compile {contract or request or method} {cid} {name}

register

Executes Register contract with the given smart contract code (contract, request).

saseul-cmd register {contract or request} {cid} {name}

publish

Executes Publish contract with the given smart contract code (method).

saseul-cmd publish {cid} {name}

send-transaction

Sends contract code execution request to SASEUL.

saseul-cmd send-transaction {contract-type} {cid}

params(json): {parameters in JSON format}

request

Sends request code execution request to SASEUL.

saseul-cmd request {request-type} {cid}

params(json): {parameters in JSON format}

log-reader

Reads app and debug logs.

saseul-cmd log-reader {list or get} {log file name} {index}

Create and Deploy your SASEUL smart contracts

1. Initiate SaseulJS CLI

You can initiate SaseulJS CLI by running the init command. The rpc-env file that contains encrypted SASEUL node host url and private key will be generated.

saseul-cmd init

set password: {your password}
Reinput a same one to confirm it: {your password}
network_name: SASEUL PUBLIC NETWORK
default_peers: ["123.234.123.234"]
private_key: 0000000000000000000your0000private0000key00000000000000000000000
ABI_OPTION: {}

app.log:
{
  "1657168050051": {
    "timestamp": "2022/07/7 PM 01:27:30 051",
    "log": "Initiating SaseulJS CLI... {config.env: src/config/config.env}"
  }
}
app.log: {
  '1656328991504': {
    timestamp: '2022/06/27 PM 08:23:11 504',
    log: 'SaseulJS CLI initiated. {rpc-env: src/config/rpc-env.json}'
  }
}

2. Create your smart contract file

You would need a template file to start coding SASEUL smart contract. You can run the create command to generate a smart contract code template.

saseul-cmd create contract Faucet 

Create code in root space? (y/n)
y
Press enter to continue.


app.log: {
  '1656301946613': {
    timestamp: '2022/06/27 PM 09:52:26 416',
    log: 'Created contract Faucet at ./code/contract/4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e/Faucet.js.'
  }
}

3. Code your smart contract

You can access smart contract ABI methods with the ABI constant.

const SaseulJS = require('saseul');
const Saseul = new SaseulJS({"network_name":"Windee Test Network","system_nonce":"CapriSun","abi":{"ethereum":false}});
const Contract = Saseul.Model.Contract;
const CODE = new Contract();
const PATH = './Faucet.json';
const NAME = 'Faucet';
const VERSION = '1';
const TYPE = 'contract';
const WRITER = '00000000000000000000000000000000000000000000';
const SPACE = '9a55a2bb8a58c26a90142252e9750d592b3c7f39f18b52cd9dc4a24bc54368a7';
const CID = '4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e';
const Parameter = Saseul.Model.Parameter;
const ABI = Saseul.Core.ABI;
const CONFIG = Saseul.CONFIG;

module.exports.build = async () => {
    return new Promise((resolve, reject) => {
        try {
            CODE.Name(NAME);
            CODE.Version(VERSION);
            CODE.Writer(WRITER);
            CODE.Space(SPACE);

            // ====================> Your code starts here <====================

            const from = ABI.Contract.Param('from');
            let from_balance = ABI.Read.ReadUniversal('balance', from, '0');

            const condition = ABI.Compare.Lt(from_balance, Saseul.Util.Math.Mul(50000, CONFIG.EXA));
            const err_msg = "You can't get SL any more. ";

            CODE.AddExecution(ABI.LegacyCondition(condition, err_msg));

            from_balance = ABI.Math.Add([from_balance, Saseul.Util.Math.Mul(100000, CONFIG.EXA)])
            CODE.AddUpdate(ABI.Write.WriteUniversal('balance', from, from_balance));

            // ====================>  Your code ends here  <====================

            resolve(CODE);

        } catch (e) {
            reject(e);
        }
    });
}

module.exports.compile = () => {
    return CODE.Compile();
}

4. Compile your smart contract

When your smart contract code is complete, you can run the compile command to generate the compiled version of your smart contract code.

saseul-cmd compile contract 4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e Faucet

app.log: {
  '1656302239538': {
    timestamp: '2022/06/27 PM 09:57:19 126',
    log: 'Compiled contract Faucet at ./code/contract/4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e/Faucet.json.'
  }
}

5. Deploy your smart contract to SASEUL

To use your smart contract code on SASEUL blockchian, you need to execute Register contract with your compiled code. You can run the register command to do this.

saseul-cmd register contract 4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e Faucet

app.log:
{
  "1656998439152": {
    "timestamp": "2022/07/5 PM 02:20:39 152",
    "log": {
      "thash": "05e308035b7c20762a6f0655b80a3092f6aeecd5cd0fa361e07e9f2d64821d001062dfd5155cb9"
    }
  }
}

For method type smart contracts,

saseul-cmd publish 4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e Fragment

app.log:
{
  "1656998439152": {
    "timestamp": "2022/07/5 PM 02:20:45 152",
    "log": {
      "thash": "05e308035b7c20762a6f0655b80a3092f6aeecd5cd0fa361e07e9f2d64821d001062dfd5155cb9"
    }
  }
}

SendTransaction and Request

SendTransaction

You can execute registered contract codes on SASEUL by running the send-transaction command.

saseul-cmd send-transaction Send 4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e

password: ************
params(json): {"to":"9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8","amount":"1000000000000000000"}

app.log:
{
  "1657082735063": {
    "timestamp": "2022/07/6 PM 01:45:35 063",
    "log": {
      "thash": "05e31ba3c8f6c0c995ac51496add5ed6a1dc7aa4b4701e0bd30ddfa0c535fcce924874b5d8623d"
    }
  }
}
app.log:
{
  "1657082737107": {
    "timestamp": "2022/07/6 PM 01:45:37 107",
    "log": {
      "transaction": {
        "type": "Send",
        "timestamp": 1657082735032000,
        "from": "0608d33c07813854cd4dd8797b4962793c360500571b",
        "to": "9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8",
        "amount": "1000000000000000000"
      },
      "public_key": "e164abbd31784a9eba637af7fb552a3c23fae4faacf410b4d7d8186a2e1f0fe2",
      "signature": "76e4ba71594874d14b9a252cfc8ae1f8b64756add2823e48c7c9400335ec272ae18974bc9e579da7fc64b8cfff159736c953291e69d316f18e2927734183a707",
      "hash": "05e31ba3c8f6c0c995ac51496add5ed6a1dc7aa4b4701e0bd30ddfa0c535fcce924874b5d8623d",
      "block": {
        "height": 7,
        "s_timestamp": 1657082736000000,
        "previous_blockhash": "05e319915c83001676106f9fee4f4bef8fbe4fefeb669dec90d487f0aee2eef622ea81bee68716",
        "blockhash": "05e31ba3d7bc004bb6466f3dd2e0d06d3a14c44efe362fc6afdc1dcbac3328793f36f64a454297",
        "seal": {
          "0608d33c07813854cd4dd8797b4962793c360500571b": {
            "hypothesis_hash": "e064fec5d41c1b2b40add2cc9cbb573c773efdc15455539fc777668da28cf8da",
            "s_timestamp": 1657082736000000,
            "public_key": "e164abbd31784a9eba637af7fb552a3c23fae4faacf410b4d7d8186a2e1f0fe2",
            "signature": "8d0a5dc9e1ae52dc19bb9c4da2c519ac8d234d59565df3b9dc08f5c67932bc4a15cac688edc094075f6867db51879cd09ad07d03fe055599e02f307ee8d0f20e"
          }
        },
        "transactions": {
          "05e31ba3c8f6c0c995ac51496add5ed6a1dc7aa4b4701e0bd30ddfa0c535fcce924874b5d8623d": {
            "transaction": {
              "type": "Send",
              "timestamp": 1657082735032000,
              "from": "0608d33c07813854cd4dd8797b4962793c360500571b",
              "to": "9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8",
              "amount": "1000000000000000000"
            },
            "public_key": "e164abbd31784a9eba637af7fb552a3c23fae4faacf410b4d7d8186a2e1f0fe2",
            "signature": "76e4ba71594874d14b9a252cfc8ae1f8b64756add2823e48c7c9400335ec272ae18974bc9e579da7fc64b8cfff159736c953291e69d316f18e2927734183a707"
          }
        },
        "universal_updates": {
          "b3c1ed9ce9df9d2531bb6e2945f044590974408f547f3574d56075e13394770d0608d33c07813854cd4dd8797b4962793c360500571b": {
            "old": "239999999999999999622000000",
            "new": "239999998999999999202000000"
          },
          "b3c1ed9ce9df9d2531bb6e2945f044590974408f547f3574d56075e13394770d9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8": {
            "old": null,
            "new": "1000000000000000000"
          },
          "c5ca2cb405daf22453b559420907bb12d7fb34519ac55d81f47829054374512f0608d33c07813854cd4dd8797b4962793c360500571b": {
            "old": "60000000000000000378000000",
            "new": "120000000000000000798000000"
          }
        },
        "local_updates": {
          "290eed314ce4d91c387028c290936b5b261e06f05d871bad42dfdf7436e89e9c00000000000000000000000000000000000000000000": {
            "old": "0",
            "new": "0"
          },
          "724d2935080d38850e49b74927eb0351146c9ee955731f4ef53f24366c5eb9b100000000000000000000000000000000000000000000": {
            "old": 6,
            "new": 7
          },
          "12194c0ef66a96758afcf4e7ddd3a0b851bba110c7dd2ffff358cbabd725b3fc00000000000000000000000000000000000000000000": {
            "old": 5,
            "new": 6
          }
        }
      },
      "status": "accept"
    }
  }
}

Request

You can execute registered request codes on SASEUL by running the request command.

saseul-cmd request GetBalance 4d343f857edb61f6b421c287536e7d32e22170784327514672604379dc3ab83e

password: ************
params(json): {"address":"9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8"}

app.log:
{
  "1657083039692": {
    "timestamp": "2022/07/6 PM 01:50:39 692",
    "log": {
      "code": 200,
      "data": {
        "balance": "1000000000000000000"
      },
      "status": "success"
    }
  }
}

Browse Logs

You can browse logs by running the log-reader command.

Get a log by Index

Run the log-reader command using get keyword with a log index.

saseul-cmd log-reader get app.log 1657083039692

{
  "1657083039692": {
    "timestamp": "2022/07/6 PM 01:50:39 692",
    "log": {
      "code": 200,
      "data": {
        "balance": "1000000000000000000"
      },
      "status": "success"
    }
  }
}

List all logs in the app.log file

Run the log-reader command using list keyword.

saseul-cmd log-reader list app.log

{
  "1657082737107": {
    "timestamp": "2022/07/6 PM 01:45:37 107",
    "log": {
      "transaction": {
        "type": "Send",
        "timestamp": 1657082735032000,
        "from": "0608d33c07813854cd4dd8797b4962793c360500571b",
        "to": "9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8",
        "amount": "1000000000000000000"
      },
      "public_key": "e164abbd31784a9eba637af7fb552a3c23fae4faacf410b4d7d8186a2e1f0fe2",
      "signature": "76e4ba71594874d14b9a252cfc8ae1f8b64756add2823e48c7c9400335ec272ae18974bc9e579da7fc64b8cfff159736c953291e69d316f18e2927734183a707",
      "hash": "05e31ba3c8f6c0c995ac51496add5ed6a1dc7aa4b4701e0bd30ddfa0c535fcce924874b5d8623d",
      "block": {

        (...)

      },
      "status": "accept"
    }
  },
  
	(...)

  "1657083039692": {
    "timestamp": "2022/07/6 PM 01:50:39 692",
    "log": {
      "code": 200,
      "data": {
        "balance": "1000000000000000000",
        "symbol": null,
        "easyView": "1",
        "network": "saseul public network",
        "abcd": "SASEUL TEST NETWORK"
      },
      "status": "success"
    }
  }
}

Get logs from archived log files

Run log-reader command using list or get keyword.

saseul-cmd log-reader list app.log-1656637812480

{
  "1656637614091": {
    "timestamp": "2022/07/1 AM 10:06:54 091",
    "log": {
      "transaction": {
        "type": "Send",
        "timestamp": 1656639474031000,
        "from": "0608d33c07813854cd4dd8797b4962793c360500571b",
        "to": "9d49ca0cc7e3bb8717676524bf669135a9fc21e56ca8",
        "amount": "3200000000000000000"
      },
      "public_key": "e164abbd31784a9eba637af7fb552a3c23fae4faacf410b4d7d8186a2e1f0fe2",
      "signature": "76e4ba71594874d14b9a252cfc8ae1f8b64756add2823e48c7c9400335ec272ae18974bc9e579da7fc64b8cfff159736c953291e69d316f18e2927734183a707",
      "hash": "05e31ba3c8f6c0c995ac51496add5ed6a1dc7aa4b4701e0bd30ddfa0c535fcce924874b5d8623d",
      "block": {

        (...)

      },
      "status": "accept"
    }
  },
  
	(...)

  "1656637652814": {
    "timestamp": "2022/07/1 AM 10:07:32 814",
    "log": {
      "code": 200,
      "data": {
        "balance": "3200000000000000000"
      },
      "status": "success"
    }
  }
}

Get debug logs

Run log-reader command for debug.log file using list or get keyword.

saseul-cmd log-reader get debug.log 1657073713580

{
  "timestamp": "2022/07/6 AM 11:15:13 580",
  "log": {
    "code": 999,
    "status": "fail",
    "msg": "You can't send more than what you have. "
  }
}

License

GPL-3.0

1.6.0

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago