You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The entry index.ts file of the tutorial, brings too much complexity, in my opinion.
Let's first take a look at the index.ts file:
// Lots of importsimport...from'...'// Some variable definitions about private-key and accountconstxxx=xxxconstxxxx=xxxx// Major function 1, constructing the transactionconstconstructHelloWorldTx=(...)=>{ ... }// Major function 2, sign and send the transactionconstsignAndSendTx=(...)=>{ ... }// Finally, the teaching steps(async()=>{// step 1
...
// step 2
...
// step n
...
})()
As we can see, the index.ts file is not so easy to read, especially for newcomers, for several reasons:
Structurally, the last part of the code (the part with steps) is important for newcomers, so it should be placed near the top
The index.ts file implements too many functions, which also affects the readability of it
Idea
So I was thinking maybe we could split index.ts (including other files like helper.ts) into more parts to improve readability of the code, and to reduce the complexity of the code.
At first, we show readers the simplest code like a magic with only a few steps, so reader can run the code with confidence. And then, if readers want to learn more about how each step works, they can jump directly to the specific file where the target function belongs.
For example, if a reader wants to know how a transaction is constructed, he can directly open the file where constructHelloWorldTx function is located.
So in my opinion, index.ts should look like this:
import{constructHelloWorldTx}from'./constructHelloWorldTx'import{signAndSendTx}from'./signAndSend'import{CHARLIE}from'./keys';(async()=>{// Step 1: declare an account for xxx purposeconstprivKey=CHARLIE.PRIVATE_KEYconstaccount=generateAccountFromPrivateKey(privKey)// Step 2: this is the message that will be written on chainconstonChainMemo: string="Hello Common Knowledge Base!"/// Step 3: construct the transactionlettxSkeleton=awaitconstructHelloWorldTx(onChainMemo);// Step 4: sign and send the transactionconsttxHash=awaitsignAndSendTx(txSkeleton,privKey);console.log(`Transaction ${txHash} sent.\n`);// Done, let's see the transaction in CKB Testnet Explorerconsole.log(`See ${CKB_TESTNET_EXPLORER}/transaction/${txHash}`);})()
And in the constructHelloWorldTx.ts file (same for other files), the structure should be equally clear, like this:
Issue
The entry
index.ts
file of the tutorial, brings too much complexity, in my opinion.Let's first take a look at the
index.ts
file:As we can see, the
index.ts
file is not so easy to read, especially for newcomers, for several reasons:index.ts
file implements too many functions, which also affects the readability of itIdea
So I was thinking maybe we could split
index.ts
(including other files likehelper.ts
) into more parts to improve readability of the code, and to reduce the complexity of the code.At first, we show readers the simplest code like a magic with only a few steps, so reader can run the code with confidence. And then, if readers want to learn more about how each step works, they can jump directly to the specific file where the target function belongs.
For example, if a reader wants to know how a transaction is constructed, he can directly open the file where
constructHelloWorldTx
function is located.So in my opinion,
index.ts
should look like this:And in the
constructHelloWorldTx.ts
file (same for other files), the structure should be equally clear, like this:The text was updated successfully, but these errors were encountered: