-
Notifications
You must be signed in to change notification settings - Fork 160
add docs for script composer #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f99c3e3
add docs
runtian-zhou 1336380
Update building-transactions.mdx
runtian-zhou b54df82
Update script-composer.mdx
runtian-zhou f670b79
Update script-composer.mdx
runtian-zhou 4d5ae09
Merge branch 'main' into runtianz/script-composer-docs
gregnazario File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,7 @@ export default { | |
"bcs-format": { | ||
title: "BCS Format", | ||
}, | ||
"script-composer": { | ||
title: "Script Composer", | ||
}, | ||
}; |
51 changes: 51 additions & 0 deletions
51
apps/nextra/pages/en/build/sdks/ts-sdk/building-transactions/script-composer.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: "Dynamically invoke chains of Move calls with ScriptComposer" | ||
--- | ||
|
||
# Dynamically invoke chains of Move calls with ScriptComposer | ||
|
||
This is so far an **expermiental** feature that is only released to [this particular](https://www.npmjs.com/package/@aptos-labs/ts-sdk/v/1.33.0-sc.0) version of typescript SDK and is subject to change. | ||
|
||
In the naive api, you only get to specify one entry function to invoke for one transaction. An advanced builder might want to be able to invoke multiple **public** Move functions inside one transaction. This is now enabled by the new `scriptComposer` api provided in the transaction builder. | ||
|
||
Here's an example of how you can invoke the api: | ||
|
||
```ts filename="example.ts" | ||
const transaction = await aptos.transaction.build.scriptComposer({ | ||
sender: singleSignerED25519SenderAccount.accountAddress, | ||
// The builder expects a closure to build up the move call sequence. | ||
builder: async (builder) => { | ||
// invoke 0x1::coin::withdraw. This function would return a value of a `coin` type. | ||
const coin = await builder.addBatchedCalls({ | ||
function: "0x1::coin::withdraw", | ||
functionArguments: [CallArgument.new_signer(0), 1], | ||
typeArguments: ["0x1::aptos_coin::AptosCoin"], | ||
}); | ||
|
||
// Passing the coin value to the 0x1::coin::coin_to_fungible_asset to convert a coin | ||
// into fungible asset. | ||
const fungibleAsset = await builder.addBatchedCalls({ | ||
function: "0x1::coin::coin_to_fungible_asset", | ||
// coin[0] represents the first return value from the first call you added. | ||
functionArguments: [coin[0]], | ||
typeArguments: ["0x1::aptos_coin::AptosCoin"], | ||
}); | ||
|
||
// Deposit the fungibleAsset converted from second call. | ||
await builder.addBatchedCalls({ | ||
function: "0x1::primary_fungible_store::deposit", | ||
functionArguments: [singleSignerED25519SenderAccount.accountAddress, fungibleAsset[0]], | ||
typeArguments: [], | ||
}); | ||
return builder; | ||
}, | ||
}); | ||
``` | ||
|
||
Behind the scene, the SDK will invoke a WASM binary to compile the series of Move calls into a `CompiledScript`. This will guarantee that the type and ability safety of Move is still being honored during the construction process. For the SDK users, this means: | ||
1. ability safety: | ||
a. If returned value does not have Drop ability, the returned value need to be consumed by subsequent calls. | ||
b. If returned value does not have Copy ability, the returned value can only be passed to subsequent calls once. | ||
2. The caller will need to make sure they pass the right values as arguments to subsequent calls. In the previous example, `0x1::coin::coin_to_fungible_asset` will expect an argument of `Coin<AptosCoin>`. | ||
|
||
This implements [AIP-102](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-102.md) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a typo in the word
expermiental
- it should beexperimental
.Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.