Skip to content

Commit 100fa38

Browse files
authored
Feature: Algob cli format for passing the arguments in script. (#850)
* Update: Have common method for both RUN and DEPLOY task
1 parent 81d8070 commit 100fa38

File tree

34 files changed

+258
-119
lines changed

34 files changed

+258
-119
lines changed

.github/workflows/05-examples.yaml

+31-27
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,29 @@ jobs:
7575
working-directory: ./examples/asa
7676
run: |
7777
pipenv run yarn algob deploy
78-
pipenv run yarn algob run --script scripts/transfer/gold-contract-sc.js
79-
pipenv run yarn algob run --script scripts/transfer/gold-delegated-lsig.js
80-
pipenv run yarn algob run --script scripts/transfer/gold-to-john.js
81-
pipenv run yarn algob run --script scripts/transfer/master-fund-john.js
82-
pipenv run yarn algob run --script scripts/transfer/tesla-to-john.js
78+
pipenv run yarn algob run scripts/transfer/gold-contract-sc.js
79+
pipenv run yarn algob run scripts/transfer/gold-delegated-lsig.js
80+
pipenv run yarn algob run scripts/transfer/gold-to-john.js
81+
pipenv run yarn algob run scripts/transfer/master-fund-john.js
82+
pipenv run yarn algob run scripts/transfer/tesla-to-john.js
8383
8484
- name: Example bond token
8585
working-directory: ./examples/bond
8686
run: |
8787
pipenv run yarn algob deploy
88-
pipenv run yarn algob run --script scripts/run/run.js
88+
pipenv run yarn algob run scripts/run/run.js
8989
9090
- name: Example crowdfunding
9191
working-directory: ./examples/crowdfunding
9292
run: |
9393
pipenv run yarn algob deploy
94-
pipenv run yarn algob run --script scripts/transfer/donate.js
94+
pipenv run yarn algob run scripts/transfer/donate.js
9595
9696
- name: Example htlc-pyteal-ts
9797
working-directory: ./examples/htlc-pyteal-ts
9898
run: |
9999
pipenv run yarn algob deploy
100-
pipenv run yarn algob run --script scripts/withdraw/htlc-withdraw.ts
100+
pipenv run yarn algob run scripts/withdraw/htlc-withdraw.ts
101101
102102
- name: Example multisig
103103
run: cd examples/multisig && pipenv run yarn algob deploy
@@ -106,20 +106,20 @@ jobs:
106106
working-directory: ./examples/nft
107107
run: |
108108
pipenv run yarn algob deploy
109-
pipenv run yarn algob run --script scripts/transfer/create-transfer-nft.js
109+
pipenv run yarn algob run scripts/transfer/create-transfer-nft.js
110110
111111
- name: Example permissioned-token
112112
working-directory: ./examples/permissioned-token
113113
run: |
114114
pipenv run yarn algob deploy
115-
pipenv run yarn algob run --script scripts/admin/issue.js
116-
pipenv run yarn algob run --script scripts/permissions/whitelist.js
117-
pipenv run yarn algob run --script scripts/user/transfer.js
118-
pipenv run yarn algob run --script scripts/admin/force-transfer.js
119-
pipenv run yarn algob run --script scripts/admin/update-reserve.js
120-
pipenv run yarn algob run --script scripts/permissions/change-perm-manager.js
121-
pipenv run yarn algob run --script scripts/admin/kill.js
122-
pipenv run yarn algob run --script scripts/user/opt-out.js
115+
pipenv run yarn algob run scripts/admin/issue.js
116+
pipenv run yarn algob run scripts/permissions/whitelist.js
117+
pipenv run yarn algob run scripts/user/transfer.js
118+
pipenv run yarn algob run scripts/admin/force-transfer.js
119+
pipenv run yarn algob run scripts/admin/update-reserve.js
120+
pipenv run yarn algob run scripts/permissions/change-perm-manager.js
121+
pipenv run yarn algob run scripts/admin/kill.js
122+
pipenv run yarn algob run scripts/user/opt-out.js
123123
124124
run-examples-batch-2:
125125
runs-on: ubuntu-20.04
@@ -160,15 +160,15 @@ jobs:
160160
working-directory: ./examples/permissioned-token-freezing
161161
run: |
162162
pipenv run yarn algob deploy
163-
pipenv run yarn algob run --script scripts/transfer/set-clear-level.js
164-
pipenv run yarn algob run --script scripts/transfer/transfer-asset.js
163+
pipenv run yarn algob run scripts/transfer/set-clear-level.js
164+
pipenv run yarn algob run scripts/transfer/transfer-asset.js
165165
166166
- name: Example permissioned-voting
167167
working-directory: ./examples/permissioned-voting
168168
run: |
169169
pipenv run yarn algob deploy
170-
pipenv run yarn algob run --script scripts/vote/vote.js
171-
pipenv run yarn algob run --script scripts/vote/result.js
170+
pipenv run yarn algob run scripts/vote/vote.js
171+
pipenv run yarn algob run scripts/vote/result.js
172172
173173
- name: Example ref-templates
174174
run: |
@@ -179,8 +179,8 @@ jobs:
179179
working-directory: ./examples/stateful-counter
180180
run: |
181181
pipenv run yarn algob deploy
182-
pipenv run yarn algob run --script scripts/interaction/call_application.js
183-
pipenv run yarn algob run --script scripts/interaction/delete_application.js
182+
pipenv run yarn algob run scripts/interaction/call_application.js
183+
pipenv run yarn algob run scripts/interaction/delete_application.js
184184
185185
run-examples-batch-3:
186186
runs-on: ubuntu-20.04
@@ -221,15 +221,19 @@ jobs:
221221
working-directory: ./examples/unique-nft-asa
222222
run: |
223223
pipenv run yarn algob deploy
224-
pipenv run yarn algob run --script scripts/run/transfer-nft.js
224+
pipenv run yarn algob run scripts/run/transfer-nft.js
225225
- name: Example inner-tx-create-assets
226226
working-directory: ./examples/inner-tx-create-assets
227227
run: |
228228
pipenv run yarn algob deploy
229-
pipenv run yarn algob run --script scripts/run/useInnerTxn.js
230-
pipenv run yarn algob run --script scripts/run/useGroupTxn.js
229+
pipenv run yarn algob run scripts/run/useInnerTxn.js
230+
pipenv run yarn algob run scripts/run/useGroupTxn.js
231231
- name: Trampoline
232232
working-directory: ./examples/trampoline
233233
run: |
234234
pipenv run yarn algob deploy
235-
pipenv run yarn algob run --script scripts/run/create-fund-app.js
235+
pipenv run yarn algob run scripts/run/create-fund-app.js
236+
- name: Script Argument Example
237+
working-directory: ./examples/script-argument-example
238+
run: |
239+
pipenv run yarn algob run scripts/script.js --arg '{"name":"this was passed as agrument"}'

docs/guide/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Check the _requirements_ section above first.\_
117117
1. Add assets and smart-contracts in the `assets` directory.
118118
1. Add deployment scripts in `scripts` directory.
119119
1. Run `yarn run algob deploy` to compile and deploy everything (all scripts nested directly in /scripts).
120-
1. Run `yarn run algob run --script scriptPath/scriptName` to run a script.
120+
1. Run `yarn run algob run scriptPath/scriptName` to run a script.
121121
1. To run `algob` on different network (by default the `default` network is used) use
122122

123123
yarn run algob --network <other_network_name> <command>

docs/guide/debugging-teal.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If it displays the `tealdbg` help, you're good to go.
2626

2727
Creating transaction data (via `goal --dryrun-dump` or SDK) could be a lengthy process, especially when using a transaction group. `Algob` provides an easy way to use debugger: by simply supplying the transactions as an input to the `TealDbg` method (same transaction parameters that we supply to [executeTx](https://algobuilder.dev/api/algob/modules.html#executeTransaction) to execute same transaction on network).
2828

29-
NOTE: You use the `TealDbg` method in an algob script, which can be run using `algob deploy`/`algob run --script` commands.
29+
NOTE: You use the `TealDbg` method in an algob script, which can be run using `algob deploy`/`algob run` commands.
3030

3131
### Using dry run for debugging a TEAL program in an algob script
3232

docs/guide/deployer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Deployer class has the following modes:
2222
- Run Mode: In run mode user can access/read checkpoints, create logs but cannot write(create) checkpoints. Files placed in nested folders (non-direct children, eg: `scripts/transfer/run-script.js`) of `scripts/` folder are considered to be run in this mode.
2323
To run a script in the _run_ mode (the script will receive deployer instance in _run_ mode\_):
2424

25-
yarn run algob run --script scripts/transfer/run-script.js
25+
yarn run algob run scripts/transfer/run-script.js
2626

2727
**Note:** In run mode user can `deploy`, `update`, `delete` or perform all these operations in a group transaction using [`executeTx`](https://algobuilder.dev/api/algob/modules.html#executetransaction) function but the `checkpoints will not be created when using run mode.`
2828

docs/guide/purestake-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242
};
4343
```
4444

45-
And while running the script, you can simply pass this cfg with the `--network` flag. (eg. `algob run --script scripts/run.js --network purestake`).
45+
And while running the script, you can simply pass this cfg with the `--network` flag. (eg. `algob run scripts/run.js --network purestake`).
4646

4747
## IndexerV2
4848

docs/guide/user-script-execution.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ layout: splash
88

99
In algob, scripts are JS files stored in the `scripts` directory and are meant to interact with the blockchain (deploy ASA, ASC1, run transactions...).
1010

11-
Scripts are run through `algob run --script` and `algob deploy` commands. `algob` is using `algob.config.js` to get information about network and accounts and is executing incremental scripts found in `scripts/`.
11+
Scripts are run through `algob run` and `algob deploy` commands. `algob` is using `algob.config.js` to get information about network and accounts and is executing incremental scripts found in `scripts/`.
1212

1313
Please see the [architecture document](https://paper.dropbox.com/published/Algorand-builder-specs--A7njBF~7_VHYy0l3m3RAKgYVBg-c4ycJtlcmEaRIbptAPqNYS6#:h2=Scripts) to see how the scripts are organized and how to use them.
1414

1515
### Script execution
1616

1717
As noted above there are two commands to execute scripts:
1818

19-
- `algob run --script`
19+
- `algob run`
2020
- `algob deploy`
2121

2222
#### Run
@@ -25,7 +25,7 @@ Runs provided scripts and doesn't save script checkpoints.
2525
Useful to query the current state of blockchain.
2626
Example:
2727

28-
algob run --script scripts/script1.js
28+
algob run scripts/script1.js
2929

3030
#### Deploy
3131

docs/tutorials/t-01.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ async function run(runtimeEnv, deployer) {
356356
module.exports = { default: run };
357357
```
358358
359-
Similarly to `scripts/0-gold.js`, this file exports one default function. This function, however, will not be run using `algob deploy`. Instead, we will use `algob run --script`:
359+
Similarly to `scripts/0-gold.js`, this file exports one default function. This function, however, will not be run using `algob deploy`. Instead, we will use `algob run`:
360360
361-
algob run --script scripts/transfer/gold-to-john.js
361+
algob run scripts/transfer/gold-to-john.js
362362
363363
The main difference between `run` and `deploy` is that:
364364

examples/asa/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ To deploy all assets simply run:
1919

2020
It will go through all files in directly placed in the `scripts/` directory (so, it doesn't go recursively into the subdirectories) and run them in the _deploy_ mode. For more information about the deployer read the [deployer guide](https://algobuilder.dev/guide/deployer.html).
2121

22-
Transfers can be executed by executing `algob run --script scripts/transfer/gold-to-john.js` and other scripts in `scripts/transfer/`.
22+
Transfers can be executed by executing `algob run scripts/transfer/gold-to-john.js` and other scripts in `scripts/transfer/`.
2323
These scripts contain logic to transfer assets to `john-account` but other accounts can be configured as well.
2424

25-
Balances can be queried by executing `algob run --script scripts/query/john-balances.js`.
25+
Balances can be queried by executing `algob run scripts/query/john-balances.js`.
2626

2727
This example also includes smart signatures in (`assets/` directory) that showcase the two different modes of operation (contract & signature delegation):
2828

@@ -58,5 +58,5 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described
5858

5959
```
6060
yarn algob deploy
61-
yarn algob run --script scripts/query/john-balances.js
61+
yarn algob run scripts/query/john-balances.js
6262
```

examples/asa/scripts/transfer/gold-delegated-lsig.debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Description:
33
* This file demonstrates the example to run teal debugger for transfer Algorand
44
* Standard Assets(ASA) & MicroAlgos using delegated lsig (between 2 user accounts).
5-
* You can run it using `algob run --script scripts/transfer/gold-delegated-lsig.debug.js`
5+
* You can run it using `algob run scripts/transfer/gold-delegated-lsig.debug.js`
66
*/
77
const { types } = require("@algo-builder/web");
88
const { Tealdbg } = require("@algo-builder/algob");

examples/crowdfunding/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ To Create Crowdfunding Stateful Smart Contract Application
3131

3232
To Donate:
3333

34-
yarn run algob run --script scripts/transfer/donate.js
34+
yarn run algob run scripts/transfer/donate.js
3535

3636
To Claim:
3737

38-
yarn run algob run --script scripts/transfer/claim.js
38+
yarn run algob run scripts/transfer/claim.js
3939

4040
To Reclaim:
4141

42-
yarn run algob run --script scripts/transfer/reclaim.js
42+
yarn run algob run scripts/transfer/reclaim.js
4343

4444
To Delete application and tranfer remaining funds to crreator:
4545

46-
yarn run algob run --script scripts/transfer/delete.js
46+
yarn run algob run scripts/transfer/delete.js
4747

4848
- Some points to be noted:
4949
- Creator can only claim funds when total goal is reached.

examples/htlc-pyteal-ts/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described
2626

2727
```
2828
yarn run algob deploy
29-
yarn run algob run --script scripts/withdraw/htlc-withdraw.ts
29+
yarn run algob run scripts/withdraw/htlc-withdraw.ts
3030
```

examples/inner-tx-create-assets/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ yarn run algob deploy
1313
## Deploy new application, asset and log id by group transaction
1414

1515
```
16-
yarn run algob run --script useGroupTxn.js
16+
yarn run algob run useGroupTxn.js
1717
```
1818

1919
## Deploy new application, asset and log id by inner transaction
2020

2121
```
22-
yarn run algob run --script useInnerTxn.js
22+
yarn run algob run useInnerTxn.js
2323
```

examples/multisig/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ You need to **_save the signed logic signature file in `examples/multisig/assets
5959
### Run
6060

6161
```
62-
yarn run algob run --script scripts/multisig_goal_sc.js
63-
yarn run algob run --script scripts/multisig_sdk_sc.js
62+
yarn run algob run scripts/multisig_goal_sc.js
63+
yarn run algob run scripts/multisig_sdk_sc.js
6464
```
6565

6666
### More information

examples/nft/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described
2525

2626
```
2727
yarn run algob deploy
28-
yarn run algob run --script scripts/transfer/create-transfer-nft.js
28+
yarn run algob run scripts/transfer/create-transfer-nft.js
2929
```

examples/permissioned-token-freezing/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ yarn run algob deploy
3838
### Run
3939

4040
```
41-
yarn run algob run --script scripts/transfer/set-clear-level.js // set minimum level(to transfer asset)
42-
yarn run algob run --script scripts/transfer/transfer-asset.js // transfer asset from Alice -> Bob
41+
yarn run algob run scripts/transfer/set-clear-level.js // set minimum level(to transfer asset)
42+
yarn run algob run scripts/transfer/transfer-asset.js // transfer asset from Alice -> Bob
4343
```
4444

4545
### More information

examples/permissioned-voting/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ To Create Vote-Token Asset and Permissioned voting application:
3535

3636
To Cast a Vote:
3737

38-
yarn run algob run --script scripts/vote/vote.js
38+
yarn run algob run scripts/vote/vote.js
3939

4040
To see the results and delete the application:
4141

42-
yarn run algob run --script scripts/vote/result.js
42+
yarn run algob run scripts/vote/result.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Script argument example
2+
3+
This example demonstrates how you can pass arguments to script.
4+
5+
The format for passing arguments:
6+
7+
`yarn algob script.js --arg '<JSON-String>'`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require("fs");
2+
3+
// check if local config in /examples exists if yes then use it, otherwise use a template
4+
// config provided by this repository.
5+
6+
let config = "../algob.config-local.js";
7+
try {
8+
fs.accessSync(config, fs.constants.F_OK);
9+
} catch {
10+
config = "../algob.config-template.js";
11+
}
12+
console.log("config file: ", config);
13+
14+
module.exports = require(config);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "script-argument-example",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "Apache-2.0",
6+
"dependencies": {
7+
"@algo-builder/algob": "workspace:*",
8+
"@algo-builder/runtime": "workspace:*",
9+
"@algo-builder/web": "workspace:*",
10+
"algosdk": "^1.22.0"
11+
},
12+
"devDependencies": {
13+
"eslint": "^8.26.0",
14+
"mocha": "^10.1.0"
15+
},
16+
"scripts": {
17+
"algob": "algob",
18+
"lint:check": "eslint --ext .js,.ts scripts",
19+
"lint": "eslint --fix --ext .js,.ts scripts",
20+
"build:docs": "echo ok",
21+
"build": "echo ok"
22+
},
23+
"mocha": {
24+
"file": "../../test/setup.js"
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
async function run(runtimeEnv, deployer, arg) {
2+
// arguments received here
3+
console.log(arg);
4+
}
5+
6+
module.exports = { default: run };

examples/signed-txn/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The standard transaction file extension is `.txn`, but the code accepts any exte
3030
### Run
3131

3232
```
33-
yarn run algob run --script scripts/transfer.js
33+
yarn run algob run scripts/transfer.js
3434
```
3535

3636
### More information

examples/trampoline/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ If you run the file fundApplication.py, it will generate two file TEAL approval.
1717

1818
```
1919
yarn run algob deploy
20-
yarn run algob run --script scripts/run/create-fund-app.js
20+
yarn run algob run scripts/run/create-fund-app.js
2121
```

packages/algob/sample-project/js/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ To run the `sample-project`:
2626

2727
- To interact with your deployments you can create a script and run it using:
2828

29-
* `algob run --script scripts/path_to/file1`
30-
* Don’t use algob run --script for deployments. This should be used only for auxiliary scripts, like ad-hock transactions (example: draining an account).
29+
* `algob run scripts/path_to/file1`
30+
* Don’t use algob run for deployments. This should be used only for auxiliary scripts, like ad-hock transactions (example: draining an account).
3131

3232
- Run tests:
3333

0 commit comments

Comments
 (0)