본문으로 건너뛰기

tokenized asset 배포

이 가이드는 asset tokenization package를 publish하고 tokenized asset과 상호작용하는 방법을 다룬다.

repository clone

asset-tokenization repository를 clone하고 setup directory로 이동한다:

$ git clone https://github.com/MystenLabs/asset-tokenization.git
$ cd asset-tokenization

.env.template file을 .env로 copy하고 dependency를 설치한다:

$ cp setup/.env.template setup/.env
$ cd setup && npm install

Sui Client CLI 초기화

정보

See "Hello, World!" for a more detailed guide on publishing packages or Sui Client CLI for a complete reference of client commands in the Sui CLI.

Before publishing your code, you must first initialize the Sui Client CLI, if you haven't already. To do so, in a terminal or console at the root directory of the project enter sui client. If you receive the following response, complete the remaining instructions:

Config file ["<FILE-PATH>/.sui/sui_config/client.yaml"] doesn't exist, do you want to connect to a Sui full node server [y/N]?

Enter y to proceed. You receive the following response:

Sui full node server URL (Defaults to Sui Testnet if not specified) :

Leave this blank (press Enter). You receive the following response:

Select key scheme to generate key pair (0 for ed25519, 1 for secp256k1, 2: for secp256r1):

Select 0. Now you should have a Sui address set up.

publishing

Sui CLI로 contract를 수동 publish하거나, 제공되는 bash script를 사용해 자동으로 deploy하고 대부분의 .env field를 채울 수 있다.

setup/.env.template file은 모든 required variable을 정의한다. 자세한 내용은 setup folder의 README를 참조한다.

package publish

두 package를 순서대로 publish한다. 먼저 asset_tokenization, 그다음 template이다.

Beginning with the Sui v1.24.1 release, the --gas-budget option is no longer required for CLI commands.

asset_tokenization 패키지

sui client publishasset_tokenization package를 수동 publish하거나 제공되는 bash script(npm run publish-asset-tokenization)로 자동 publish할 수 있다. 이 script는 .env file의 SUI_NETWORK, ASSET_TOKENIZATION_PACKAGE_ID, REGISTRY도 채운다.

수동으로 publish하려면 move/asset_tokenization directory에서 다음을 실행한다:

$ sui client publish --gas-budget <GAS-BUDGET>

package가 성공적으로 deploy되면 다음이 표시된다:

UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING asset_tokenization
Successfully verified dependencies on-chain against source.

생성된 object의 package IDregistry ID.env file에 저장한다. 그런 다음 Move.toml을 수정한다. [addresses] section 아래에서 0x0을 같은 package ID로 바꾼다. 선택적으로 [package] section 아래에 published-at = <package ID>를 추가한다(sui client publish 실행 후 Move.lock file이 보이면 이 단계는 필요하지 않다).

자세한 내용은 setup folder의 README를 참조한다.

template 패키지

sui client publishtemplate package를 수동 publish하거나, npm run publish-template을 사용해 WASM library를 통해 자동 publish할 수 있다. automatic flow를 실행하기 전에 asset_tokenization/Move.toml[addresses] section에 asset_tokenization package address가 설정되어 있고 original deployment와 일치하는지 확인한다. Move.lock file이 없으면 published-at field도 최신 package deployment address로 채운다.

수동으로 publish하려면 move/template directory에서 다음을 실행한다:

$ sui client publish --gas-budget <GAS-BUDGET>

package가 성공적으로 deploy되면 다음이 표시된다:

UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY asset_tokenization
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING template
Successfully verified dependencies on-chain against source.

생성된 object의 package ID, asset metadata ID, asset cap ID, Publisher ID.env file에 저장한다.

자세한 내용은 setup folder의 README를 참조한다.

WebAssembly (WASM)과 template package

move-binary-format-wasm Sui repo subfolder에서 WASM library의 public-facing reference를 찾을 수 있다.

WASM 기능은 browser environment에서 Move bytecode serialization 및 deserialization을 가능하게 하여 local build environment 없이 existing contract를 edit할 수 있게 한다. asset tokenization에서는 browser에서 직접 새 asset type을 만들고 publish할 수 있다.

bytecode 조작

주의

template package를 수정하면 이 process를 반복해야 한다. constant name 변경 같은 일부 alteration은 생성된 bytecode에 영향을 주지 않는다.

WASM library는 template module의 compiled bytecode를 조작한다. 이를 가져오려면 template folder 안으로 이동해 다음을 실행한다:

$ xxd -c 0 -p build/template/bytecode_modules/template.mv | head -n 1
Click to open
console response

response는 다음과 유사하다:

a11ceb0b060000000a010010021026033637046d0a05776807df01ec0108cb03800106cb043
e0a8905050c8e0549001303140107010d01120215021602170004020001000c01000101010c
010001020307000302070100000403070006050200070607000009000100010a0a0b0102021
2050700030c010401000311060401000418050800050e0601010c050f1001010c06100d0e00
070b050300030304030109060c070f02080007080600040b040108070b010108000b0201080
00b04010807010807010b04010900010a020109000108030108050108000809000308030805
08050b0401080701070806020b010109000b02010900010b02010800010608060105010b010
10800020900050841737365744361700d41737365744d65746164617461064f7074696f6e06
537472696e670854454d504c415445095478436f6e746578740355726c0561736369690b647
56d6d795f6669656c6404696e6974096e65775f6173736574156e65775f756e736166655f66
726f6d5f6279746573046e6f6e65066f7074696f6e137075626c69635f73686172655f6f626
a6563740f7075626c69635f7472616e736665720673656e64657204736f6d6506737472696e
670874656d706c6174650f746f6b656e697a65645f6173736574087472616e736665720a747
85f636f6e746578740375726c04757466380000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000100000000000000000000000000000000000000000000000000000000000000
02d9ebdef1e3cb5eb135362572b18faeb61259afe651a463f1384745ebd7fd51da030864000
000000000000a02070653796d626f6c0a0205044e616d650a020c0b4465736372697074696f
6e0a02090869636f6e5f75726c0101010a02010000020108010000000002230704070621040
738000c02050b0704110938010c020b020c050b0007000701110207021105070311050b0507
050a0138020c040c030b0438030b030b012e110838040200

output을 copy하여 bytecode-template.tsgetBytecode method return statement에 paste한다.

template package는 2개의 module을 포함하므로 genesis module의 bytecode도 가져와야 한다. 이 bytecode는 edit되지 않지만 template module을 deploy하는 데 필요하다. template folder로 이동해 다음을 실행한다:

$ xxd -c 0 -p build/template/bytecode_modules/genesis.mv | head -n 1

output을 copy하여 genesis_bytecode.ts의 bytecode constant에 paste한다.

이 setup을 마치면 library가 bytecode를 deserialize하고 edit을 적용한 뒤 publish를 위해 다시 serialize할 수 있다.

template module constant

template module은 WASM library가 수정할 수 있는 constant 집합을 정의한다:

...
const TOTAL_SUPPLY: u64 = 100;
const SYMBOL: vector<u8> = b"Symbol";
const NAME: vector<u8> = b"Name";
const DESCRIPTION: vector<u8> = b"Description";
const ICON_URL: vector<u8> = b"icon_url";
const BURNABLE: bool = true;
...

edit과 deploy를 수행하는 TypeScript code는 이러한 constant를 식별하고 update한다:

...
const template = getBytecode();

const compiledModule = new CompiledModule(
JSON.parse(wasm.deserialize(template))
)
.updateConstant(0, totalSupply, "100", "u64")
.updateConstant(1, symbol, "Symbol", "string")
.updateConstant(2, asset_name, "Name", "string")
.updateConstant(3, description, "Description", "string")
.updateConstant(4, iconUrl, "icon_url", "string")
.updateConstant(5, burnable, "true", "bool")
.changeIdentifiers({
template: moduleName,
TEMPLATE: moduleName.toUpperCase(),
});

const bytesToPublish = wasm.serialize(JSON.stringify(compiledModule));
...

updateConstant method는 4개의 argument를 받는다:

  • idx: constant pool 안에서 constant의 index이며 0부터 sequential하게 시작한다.
  • value: constant의 updated value이다.
  • expectedValue: constant의 current value이며, 실수로 잘못된 constant를 update할 risk를 줄이는 데 사용된다.
  • expectedType: 같은 이유로 사용하는 constant의 current type이다.

changeIdentifiers method는 module name 및 struct name 같은 identifier를 update한다. current identifier name을 key로, 원하는 name을 value로 갖는 JSON object를 받는다.

변경된 template module을 deploy하려면 build하고 publish한다:

...
const tx = new Transaction();
tx.setGasBudget(100000000);
const [upgradeCap] = tx.publish({
modules: [[...fromHex(bytesToPublish)], [...fromHex(genesis_bytecode)]],
dependencies: [
normalizeSuiObjectId("0x1"),
normalizeSuiObjectId("0x2"),
normalizeSuiObjectId(packageId),
],
});

tx.transferObjects(
[upgradeCap],
tx.pure(signer.getPublicKey().toSuiAddress(), "address")
);
...

modules array에는 edit된 template module과 genesis module이라는 2개의 element가 포함된다. packageIdasset_tokenization package가 deploy된 address이다.

TypeScript command

publish 후 TypeScript setup script를 사용해 tokenized asset과 상호작용한다. 사용할 수 있는 command의 전체 reference는 Asset Tokenization TypeScript CLI Reference를 참조한다.