Sui Client PTB CLI
client ptb 명령어를 사용하면 CLI 또는 bash 스크립트를 통해 programmerble transaction block(PTB)에서 실행할 transaction을 지정할 수 있다.
이 문서의 예제는 bash 셸 환경에서 테스트되었다. 사용하는 셸이 입력 값을 해석하는 방식에 따라 결과가 다를 수 있다(예: zsh는 대괄호로 전달되는 값에 따옴표:"[]"를 사용해야 하는 반면; bash는 따옴표 없이도 값을 사용할 수 있다). Windows에서는 전달되는 인수에 따옴표를 더 추가해야하는 경우도 있다(예: --assign "forge @<FORGE-ID>" ).
Commands
다음 목록은 sui client ptb 명령에 사용할 수 있는 모든 인수를 나열한 것이다. 자세한 도움말을 보려면 --help 옵션을 사용한다. 여기에는 이 명령 사용 방법에 대한 예제가 포함되어 있다.
Build, preview, and execute programmable transaction blocks. Depending on your shell, you might have to use quotes around arrays or other passed values. Use --help to see examples for how to use the core functionality of this
command.
Usage: sui client ptb [OPTIONS]
Options:
--assign <NAME> <VALUE>
Assign a value to a variable name to use later in the PTB.
If only a name is supplied, the result of the last transaction is bound to that name.
If a name and value are supplied, then the name is bound to that value.
Examples:
--assign MYVAR 100
--assign X [100,5000]
--split-coins gas [1000, 5000, 75000]
--assign new_coins # bound new_coins to the result of previous transaction
--dry-run
Perform a dry run of the PTB instead of executing it.
--gas-coin <ID>
The object ID of the gas coin to use. If not specified, it will try to use the first gas coin that it finds that has at least the requested gas-budget balance.
--gas-budget <MIST>
An optional gas budget for this PTB (in MIST). If gas budget is not provided, the tool will first perform a dry run to estimate the gas cost, and then it will execute the transaction. Please note that this incurs a small
cost in performance due to the additional dry run call.
--make-move-vec <TYPE> <[VALUES]>
Given n-values of the same type, it constructs a vector. For non objects or an empty vector, the type tag must be specified.
Examples:
--make-move-vec <u64> []
--make-move-vec <u64> [1, 2, 3, 4]
--make-move-vec <std::option::Option<u64>> [none,none]
--make-move-vec <sui::coin::Coin<sui::sui::SUI>> [gas]
--merge-coins <INTO_COIN> <[COIN OBJECTS]>
Merge N coins into the provided coin.
Examples:
--merge-coins @coin_object_id [@coin_obj_id1, @coin_obj_id2]
--move-call <PACKAGE::MODULE::FUNCTION> <TYPE_ARGS> <FUNCTION_ARGS>
Make a move call to a function.
Examples:
--move-call std::option::is_none <u64> none
--assign a none
--move-call std::option::is_none <u64> a
--split-coins <COIN> <[AMOUNT]>
Split the coin into N coins as per the given array of amounts.
Examples:
--split-coins gas [1000, 5000, 75000]
--assign new_coins # bounds the result of split-coins command to variable new_coins
--split-coins @coin_object_id [100]
--transfer-objects <[OBJECTS]> <TO>
Transfer objects to the specified address.
Examples:
--transfer-objects [obj1, obj2, obj3] @address
--split-coins gas [1000, 5000, 75000]
--assign new_coins # bound new_coins to result of split-coins to use next
--transfer-objects [new_coins.0, new_coins.1, new_coins.2] @to_address
--publish <MOVE_PACKAGE_PATH>
Publish the Move package. It takes as input the folder where the package exists.
Examples:
--move-call sui::tx_context::sender
--assign sender
--publish "."
--assign upgrade_cap
--transfer-objects "[upgrade_cap]" sender
--upgrade <MOVE_PACKAGE_PATH>
Upgrade the move package. It takes as input the folder where the package exists.
--preview
Preview the list of PTB transactions instead of executing them.
--serialize-unsigned-transaction
Instead of executing the transaction, serialize the bcs bytes of the unsigned transaction data using base64 encoding.
--serialize-signed-transaction
Instead of executing the transaction, serialize the bcs bytes of the signed transaction data using base64 encoding.
--summary
Show only a short summary (digest, execution status, gas cost). Do not use this flag when you need all the transaction data and the execution effects.
--warn-shadows
Enable shadow warning when the same variable name is declared multiple times. Off by default.
--json
Return command outputs in json format.
-h, --help
Print help (see a summary with '-h')
Design philosophy and concepts
CLI PTB 지원의 핵심 철학은 사용자가 명령줄에서 PTB를 구성하고 실행할 수 있도록 하는 것이다. Bash 스크립트를 사용하여 명령줄에서와 마찬가지로 PTB를 구성하고 실행할 수 있으므로 다양한 작업을 자동화하는 데 뛰어난 유연성을 제공한다.
기존의 traditional PTB 관련 개념을 활용하는 것 외에도, 이 명령에 몇 가지 새롭고 중요한 개념을 소개한다.
다음 예제들은 모두 bash 셸 환경에서 테스트되었으며, 사용하는 셸이 입력값을 해석하는 방식에 따라 결과가 다를 수 있다(예: zsh는 값을 괄호로 묶어 전달해야 한다: "[]"; bash는 따옴표 없이도 값을 허용한다).
Types
간혹 CLI PTB에서는 값이나 변수 유형을 지정하는 경우가 있다. 예를 들어, 다음 예제에서는 0x1::option::is_none 함수를 호출할 때 <u64> 유형을 제공해야 한다.
$ sui client ptb \
--assign my_variable none \
--move-call 0x1::option::is_none "<u64>" my_variable \
--gas-budget 50000000
여러 데이터 유형을 전달하려면 쉼표로 구분한다:
...
--move-call package::module::function "<u64,u8,u256>" \
...
Strings
CLI PTB는 문자열 리터럴을 입력으로 지원하며, 이러한 문자열은 vector<u8> , std::ascii::String 및 std::string::String 매개변수의 입력으로 사용할 수 있는 순수 값으로 인코딩된다. 다음 예제는 "Hello, world" 문자열을 $PKG 패키지(해당 패키지 ID는 환경 변수에 저장됨)의 함수 m::f 에 전달하는 transaction 블록을 미리 보여준다.
$ sui client ptb --move-call "$PKG::m::f" '"Hello, world"' --gas-budget 10000000 --preview
큰따옴표로 묶인 문자열 리터럴은 bash 와 같은 셸에서도 유효한 구문인 경우가 많으므로 명령줄에서 PTB를 입력할 때는 이전 예제처럼 큰따옴표가 그대로 해석되도록 전체 문자열을 작은따옴표로 묶어야 한다.
Addresses and Object IDs
You can pass literal addresses and objects IDs by prefixing them with '@'. This is needed to distinguish a hexadecimal value from an address in some situations.
For addresses that are in your local wallet, you can use their alias instead (passing them without '@', for example, --transfer-objects my_alias).
다음은 transfer-objects 와 gas-coin 에 대한 몇 가지 예시이다:
$ sui client ptb --transfer-objects "[ARRAY_OF_OBJECTS]" @0x02a212de6a9dfa3a69e22387acfbafbb1a9e591bd9d636e7895dcfc8de05f331 --gas-coin @0x00002819ee07a66e53800495ccf5eeade8a02054a2e0827546c70e4b226f0495