Skip to content

Commit

Permalink
feat: updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Alive24 committed Feb 11, 2025
1 parent 1027a6f commit dffebdd
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 195 deletions.
19 changes: 2 additions & 17 deletions packages/examples/src/pauseableUdt/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,9 @@ const pudtnPauseTx = (
[targetReceiverBScript.hash()],
)
).res;
await render(pudtnPauseTx);

await pudtPauseTx.completeFeeBy(signer);
await pudtnPauseTx.completeFeeBy(signer);
// NOTE: This would fail for 36 ("Nothing To DO") if run again because it's already paused and it would be deduped. Run unpause before pausing them again
const pudtPauseTxHash = await signer.sendTransaction(pudtPauseTx);
console.log(pudtPauseTxHash);
// "0xc8df6b7edaa295f4044107e5c7f5b20fffe6e36e37fcf6513337c2be8c354e39"
const pudtnPauseTxHash = await signer.sendTransaction(pudtnPauseTx);
console.log(pudtnPauseTxHash);
// "0x04fd05e091189d9beae525decd22d61cd8d63bd2ce6949369961fca7fa63a27b"

// NOTE: This won't change because you need to upgrade the script to see the change
const pudtnPaused = await pudtn.enumeratePaused();
console.log(pudtnPaused);
// {"res":[],"cellDeps":[]}

// NOTE: This might be delayed if the transaction is not yet confirmed
const pudtPaused = await pudt.enumeratePaused();
console.log(pudtPaused);
// {"res":["0x787e97af6860c58fcecd12653714330c003f5b960e09f027295a49e3c41d609f","0x0ac6e7d7ed8d8ac0832992f106dbebbd71a2cfa4791ef621dec081a047f7668d","0xa320a09489791af2e5e1fe84927eda84f71afcbd2c7a65cb419464fe46e75085","0x779c916fc89f7c7d03c97d7a2aa5cf4f854d4f279ef0a89f8568dc65e744b3a6"],"cellDeps":[{"txHash":"0xc8df6b7edaa295f4044107e5c7f5b20fffe6e36e37fcf6513337c2be8c354e39","index":"0"}]}
await render(pudtPauseTx);
await render(pudtnPauseTx);
10 changes: 1 addition & 9 deletions packages/examples/src/pauseableUdt/unpause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ const pudtUnpauseTx = (
[targetReceiverBScript.hash()],
)
).res;
await render(pudtUnpauseTx);

await pudtUnpauseTx.completeFeeBy(signer);
const pudtUnpauseTxHash = await signer.sendTransaction(pudtUnpauseTx);
console.log(pudtUnpauseTxHash);
// "0x7715e78b4c5ded8928027c6aa610468eafce81c88e48e1267c1b787f52bb4929"

// NOTE: This might be delayed if the transaction is not yet confirmed
const pudtPaused = await pudt.enumeratePaused();
console.log(pudtPaused);
// {"res":["0x787e97af6860c58fcecd12653714330c003f5b960e09f027295a49e3c41d609f"],"cellDeps":[{"txHash":"0x7715e78b4c5ded8928027c6aa610468eafce81c88e48e1267c1b787f52bb4929","index":"0"}]}
await render(pudtUnpauseTx);
20 changes: 10 additions & 10 deletions packages/examples/src/ssri/getMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
const scriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
// TypeID args. Change it to the args of the Type ID script of your Script
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!scriptCell) {
throw new Error("Script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const scriptCodeHash = scriptCell.cellOutput.type?.hash();
if (!scriptCodeHash) {
throw new Error("Script code hash not found");
}

const pudt = new ccc.ssri.Trait(pudtScriptCell.outPoint, executor);
const script = new ccc.ssri.Trait(scriptCell.outPoint, executor);

const pudtMethods = await pudt.getMethods();
const scriptMethods = await script.getMethods();

console.log(pudtMethods);
console.log(scriptMethods);
///
// {"res":["0x6f2a4642323106f8","0x58f02409de9de7b1","0xb43d1128f8726c19","0xc78a67cec2fcc54f","0x35fa711c8c918aad","0x2f87f08056af234d","0xa306f89e40893737","0x235c6c5c6ee04b08","0x9adf445d336222e1","0x2e04fafee9f986ea","0x03cd9ce840759d42","0x849def40c0e9a525","0x43f92b1ceda6fa2b"],"cellDeps":[]}
20 changes: 10 additions & 10 deletions packages/examples/src/ssri/hasMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
const scriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
// TypeID args. Change it to the args of the Type ID script of your Script
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!scriptCell) {
throw new Error("Script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const scriptCodeHash = scriptCell.cellOutput.type?.hash();
if (!scriptCodeHash) {
throw new Error("Script code hash not found");
}

const pudt = new ccc.ssri.Trait(pudtScriptCell.outPoint, executor);
const script = new ccc.ssri.Trait(scriptCell.outPoint, executor);

const pudtHasMethods = await pudt.hasMethods([
const scriptHasMethods = await script.hasMethods([
"SSRI.get_methods",
"SSRI.has_methods",
"SSRI.version",
Expand All @@ -39,7 +39,7 @@ const pudtHasMethods = await pudt.hasMethods([
"UNKNOWN",
]);

console.log(pudtHasMethods);
console.log(scriptHasMethods);
///
// {"res":[true,true,true,true,true,true,true,true,true,true,true,true,true,false],"cellDeps":[]}
///
20 changes: 10 additions & 10 deletions packages/examples/src/ssri/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
const scriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
// TypeID args. Change it to the args of the Type ID script of your Script
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!scriptCell) {
throw new Error("Script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const scriptCodeHash = scriptCell.cellOutput.type?.hash();
if (!scriptCodeHash) {
throw new Error("Script code hash not found");
}

const pudt = new ccc.ssri.Trait(pudtScriptCell.outPoint, executor);
const script = new ccc.ssri.Trait(scriptCell.outPoint, executor);

const pudtVersion = await pudt.version();
const scriptVersion = await script.version();

console.log(pudtVersion);
console.log(scriptVersion);
///
// {"res":"0","cellDeps":[]}
///
22 changes: 11 additions & 11 deletions packages/examples/src/udt/decimals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
const udtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!udtScriptCell) {
throw new Error("udt script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const udtCodeHash = udtScriptCell.cellOutput.type?.hash();
if (!udtCodeHash) {
throw new Error("udt code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
const udtType = {
codeHash: udtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.Udt(pudtScriptCell.outPoint, pudtType, {
const udt = new ccc.udt.Udt(udtScriptCell.outPoint, udtType, {
executor,
});

const pudtDecimals = await pudt.decimals();
const udtDecimals = await udt.decimals();

console.log(pudtDecimals);
console.log(udtDecimals);
///
// {"res":"6","cellDeps":[]}
///
22 changes: 11 additions & 11 deletions packages/examples/src/udt/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
const udtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!udtScriptCell) {
throw new Error("udt script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const udtCodeHash = udtScriptCell.cellOutput.type?.hash();
if (!udtCodeHash) {
throw new Error("udt code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
const udtType = {
codeHash: udtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.Udt(pudtScriptCell.outPoint, pudtType, {
const udt = new ccc.udt.Udt(udtScriptCell.outPoint, udtType, {
executor,
});

const pudtIcon = await pudt.icon();
console.log(pudtIcon);
const udtIcon = await udt.icon();
console.log(udtIcon);
// {"res":"Pausable UDT without external data","cellDeps":[]}
30 changes: 13 additions & 17 deletions packages/examples/src/udt/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");
const signerAddress = await signer.getRecommendedAddress();
const {script: signerLock} = await ccc.Address.fromString(signerAddress, signer.client);

const pudtScriptCell = await signer.client.findSingletonCellByType({
const udtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!udtScriptCell) {
throw new Error("udt script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const udtCodeHash = udtScriptCell.cellOutput.type?.hash();
if (!udtCodeHash) {
throw new Error("udt code hash not found");
}
const signerPudtType = {
codeHash: pudtCodeHash,
const signerUdtType = {
codeHash: udtCodeHash,
hashType: "type",
args: signerLock.hash()
};

const signerPudt = new ccc.udt.Udt(pudtScriptCell.outPoint, signerPudtType, {
const signerUdt = new ccc.udt.Udt(udtScriptCell.outPoint, signerUdtType, {
executor,
});

Expand All @@ -49,8 +49,8 @@ const { script: lockB } = await ccc.Address.fromString(
signer.client,
);

const signerPudtMintTx = (
await signerPudt.mint(signer, [
const signerUdtMintTx = (
await signerUdt.mint(signer, [
{
to: lockA,
amount: 1000000000000000000,
Expand All @@ -62,9 +62,5 @@ const signerPudtMintTx = (
])
).res;

await signerPudtMintTx.completeFeeBy(signer);
await render(signerPudtMintTx);

const signerPudtMintTxHash = await signer.sendTransaction(signerPudtMintTx);

console.log(signerPudtMintTxHash);
await signerUdtMintTx.completeFeeBy(signer);
await render(signerUdtMintTx);
22 changes: 11 additions & 11 deletions packages/examples/src/udt/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
const udtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
if (!udtScriptCell) {
throw new Error("udt script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
const udtCodeHash = udtScriptCell.cellOutput.type?.hash();
if (!udtCodeHash) {
throw new Error("udt code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
const udtType = {
codeHash: udtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.Udt(pudtScriptCell.outPoint, pudtType, {
const udt = new ccc.udt.Udt(udtScriptCell.outPoint, udtType, {
executor,
});

const pudtName = await pudt.name();
console.log(pudtName);
const udtName = await udt.name();
console.log(udtName);
// {"res":"Pausable UDT without external data","cellDeps":[]}
Loading

0 comments on commit dffebdd

Please sign in to comment.