-
Notifications
You must be signed in to change notification settings - Fork 26
Adds Transfer Wrapped Assets guide to Token Bridge section #461
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
base: main
Are you sure you want to change the base?
Conversation
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.
Great Job!
Only two minor things.
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.
LGTM from a technical perspective. The page needs to be added to the .pages
file for visibility.
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.
Pull Request Overview
This PR adds a new end-to-end guide for transferring wrapped assets via the Token Bridge, updates navigation and index files, and provides full code and terminal snippets.
- Introduces
transfer-wrapped-assets.md
with attestation, transfer, and redemption flows - Updates sidebar (
.pages
) and LLMS index to include the new guide - Supplies helper functions and TypeScript snippets demonstrating the complete transfer process
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
products/token-bridge/guides/transfer-wrapped-assets.md | New guide covering attestation, automatic/manual transfer, VAA fetching, and redemption |
products/token-bridge/guides/.pages | Added navigation entry for the new guide |
llms.txt | Added LLMS index entry pointing to the new guide |
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/helpers.ts | Helper functions for signer setup and decimal conversion |
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/transfer01.ts | Complete transfer flow implementation in TypeScript |
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/terminal01.html | Initial terminal output for attestation check |
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/terminal02.html | Terminal output for attestation flow |
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/terminal03.html | Terminal output for manual transfer completion |
Comments suppressed due to low confidence (4)
products/token-bridge/guides/transfer-wrapped-assets.md:11
- The introduction mentions transferring from Moonbase Alpha to Solana, but the PR description states Ethereum Sepolia. Update to reflect the correct source and destination chains consistently.
This guide demonstrates the transfer of wrapped assets using the Token Bridge protocol via the TypeScript SDK. This example will transfer an arbitrary ERC-20 token from Moonbase Alpha to Solana but can be adapted for any supported chains. View this list of chains with [deployed Token Bridge contracts](/products/reference/contract-addresses/#token-bridge){target=\_blank} to verify if your desired source and destination chains are supported.
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/transfer01.ts:133
- The comment says 'source chain' but the code uses
destinationChain.config.nativeTokenDecimals
. Update the comment to reference the destination chain or adjust the logic if needed.
// Get the decimals for the source chain
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/transfer01.ts:82
- Redeclaring
const payer
inside the same block shadows the earlier variable and will cause a syntax error. Rename this variable (e.g.,destPayer
) to avoid redeclaration.
const payer = toNative(
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/helpers.ts:38
EVM_PRIVATE_KEY
is referenced but not defined or imported. Useprocess.env.EVM_PRIVATE_KEY
(or your keystore API) to load environment variables securely.
).getSigner(await chain.getRpc(), EVM_PRIVATE_KEY!);
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/transfer01.ts
Outdated
Show resolved
Hide resolved
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/helpers.ts
Show resolved
Hide resolved
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.
Great work! Just a few minor adjustments to make, almost ready to go!
.snippets/code/products/token-bridge/guides/transfer-wrapped-assets/terminal01.html
Outdated
Show resolved
Hide resolved
Co-authored-by: Erin Shaben <[email protected]>
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.
LGTM! 🚀
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.
Sweet, it's looking good!
I added a few comments with ideas that came up while reviewing. Some might not belong on this page, but they could be useful to consider for elsewhere.
Also, I noticed there were some comments from my last review that weren't marked as resolved. They're hidden when you look at the main PR page, so maybe go through and expand all convos to just double-check all the things.
|
||
Follow these steps to add the rest of the logic to initiate the token transfer on the source chain: | ||
|
||
1. Open your `transfer.ts` file and add the following code: |
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.
Where in the transfer.ts
file does this need to be added? Although might be obvious to add it to the end, let's make it super clear
|
||
- Defines the transfer as automatic or manual. To use automatic transfer, both the source and destination chain must have an existing `tokenBridgeRelayer` contract. You can check the list of [deployed `tokenBridgeRelayer` contracts](https://github.com/wormhole-foundation/wormhole-sdk-ts/blob/a48c9132015279ca6a2d3e9c238a54502b16fc7e/core/base/src/constants/contracts/tokenBridgeRelayer.ts){target=\_blank} in the Wormhole SDK repo to see if your desired chains are supported. | ||
- Sets an optional amount for native gas drop-off. This option allows you to send a small amount of the destination chain's native token for gas fees. Native gas drop-off is currently only supported for automatic transfers. | ||
- Builds the transfer object, initiates the transfer, signs and sends the transaction. |
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.
- Builds the transfer object, initiates the transfer, signs and sends the transaction. | |
- Builds the transfer object, initiates the transfer, signs the transaction, and sends it. |
|
||
This code does the following: | ||
|
||
- Defines the transfer as automatic or manual. To use automatic transfer, both the source and destination chain must have an existing `tokenBridgeRelayer` contract. You can check the list of [deployed `tokenBridgeRelayer` contracts](https://github.com/wormhole-foundation/wormhole-sdk-ts/blob/a48c9132015279ca6a2d3e9c238a54502b16fc7e/core/base/src/constants/contracts/tokenBridgeRelayer.ts){target=\_blank} in the Wormhole SDK repo to see if your desired chains are supported. |
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.
- Defines the transfer as automatic or manual. To use automatic transfer, both the source and destination chain must have an existing `tokenBridgeRelayer` contract. You can check the list of [deployed `tokenBridgeRelayer` contracts](https://github.com/wormhole-foundation/wormhole-sdk-ts/blob/a48c9132015279ca6a2d3e9c238a54502b16fc7e/core/base/src/constants/contracts/tokenBridgeRelayer.ts){target=\_blank} in the Wormhole SDK repo to see if your desired chains are supported. | |
- Defines the transfer as automatic or manual. For automatic transfers, both the source and destination chain must have an existing `TokenBridgeRelayer` contract, which listens for and completes transfers on your behalf. You can check the list of [deployed `TokenBridgeRelayer` contracts](https://github.com/wormhole-foundation/wormhole-sdk-ts/blob/a48c9132015279ca6a2d3e9c238a54502b16fc7e/core/base/src/constants/contracts/tokenBridgeRelayer.ts){target=\_blank} in the Wormhole SDK repo to see if your desired chains are supported. |
I think it's implied, but can add a tiny bit more context here to make it super clear
|
||
You can now go on to [initiate the transfer](#initiate-transfer-on-source-chain) on the source chain. | ||
|
||
## Initiate Transfer on Source Chain |
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.
I think it might be nice to briefly describe the difference between automatic vs manual - it is sort of covered in the comments in the code but might be nice to provide this info explicitly and upfront.
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.
I tried to look at this as key differences that affect how you write the script. See what you think....
|
||
1. Open your `transfer.ts` file and add the following code: | ||
|
||
```typescript title="transfer.ts" |
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.
I still think tabs for automatic vs manual might be helpful here, because if going with manual there's some automatic variables that aren't necessary, and if going with automatic, there's extra unnecessary logic for completing the transfer
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.
For manual transfers, maybe showcase the isTransferCompleted
function at the end?
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.
I added the tabs and I like it! Attempted to separate these out to just what's needed for manual and auto on each tab but I haven't tested them yet.
- Sets an optional amount for native gas drop-off. This option allows you to send a small amount of the destination chain's native token for gas fees. Native gas drop-off is currently only supported for automatic transfers. | ||
- Builds the transfer object, initiates the transfer, signs and sends the transaction. | ||
- If the transfer is automatic, the flow ends. Otherwise, the script waits for the signed VAA confirming the transaction on the source chain. The signed VAA is then submitted to the destination chain to claim the tokens and complete the manual transfer. | ||
|
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.
What if a user wants to send a payload? What would that look like? I think this is the time to go over all of the different options available
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.
Also, I've started to think about automatic transfers a bit more, we don't really mention anything about fees, what are the fees, how do they paid for, how much can be swapped for native tokens. Maybe we can briefly mention some of these things here, maybe other items would be better addressed in a separate guide (i.e., reference docs on maxSwapAmount function could have an example on how to use that function to get the max amount)
|
||
2. Run the script with the following command: | ||
```bash | ||
npx tsx transfer.ts |
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.
This comment still applies
Co-authored-by: Erin Shaben <[email protected]>
Description
Replaces PR #459, which I will close.
This PR creates the Transfer Wrapped Assets guide for the Token Bridge product section. The demo project does the following:
TODO items: missing links to pending Token Bridge-related guides for Next Steps
Checklist
[x ] Required - I have added a label to this PR 🏷️
[ x] Required - I have run my changes through Grammarly
[ n/a ] If pages have been moved, I have created redirects in the wormhole-mkdocs repo