diff --git a/README.md b/README.md index 3abc32007..2bc748d65 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,35 @@ npm install @wormhole-foundation/sdk This package combines all the individual packages in a way that makes setup easier while still allowing for tree shaking. +## Troubleshooting TypeScript Compatibility + +If you encounter issues when integrating the Wormhole SDK into a TypeScript project, such as errors related to dependencies like `@coral-xyz/anchor`, `@cosmjs`, or `ethers`, here are some steps to resolve them: + +1. **Ensure all dependencies are installed correctly**: + ```bash + npm install @wormhole-foundation/sdk @coral-xyz/anchor @cosmjs ethers + +2. **Adjust your `tsconfig.json`** to include the following settings: + ```json + { + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true + } + } + + 3. Check for conflicting versions of dependencies, particularly when using multiple packages that depend on the same underlying libraries (e.g., `@cosmjs`). +Ensure that all dependencies are using compatible versions. + +4. **Consider using `npm dedupe`** to resolve any version conflicts: + ```bash + npm dedupe + +If issues persist, refer to the specific package documentation or reach out to the community for further assistance. + ### Advanced Alternatively, for an advanced user, install a specific set of the packages published. diff --git a/examples/src/cctp.ts b/examples/src/cctp.ts index 1861fd023..0b81da4e0 100644 --- a/examples/src/cctp.ts +++ b/examples/src/cctp.ts @@ -59,6 +59,7 @@ AutoRelayer takes a 0.1usdc fee when xfering to any chain beside goerli, which i // ); })(); +// Enhanced error handling and comments for cctpTransfer function async function cctpTransfer( wh: Wormhole, src: SignerStuff, @@ -69,21 +70,41 @@ async function cctpTransfer( nativeGas?: bigint; }, ) { - // EXAMPLE_CCTP_TRANSFER - const xfer = await wh.circleTransfer( - // amount as bigint (base units) - req.amount, - // sender chain/address - src.address, - // receiver chain/address - dst.address, - // automatic delivery boolean - req.automatic, - // payload to be sent with the transfer - undefined, - // If automatic, native gas can be requested to be sent to the receiver - req.nativeGas, - ); + try { + // Initiating a Circle Transfer + const xfer = await wh.circleTransfer( + req.amount, + src.address, + dst.address, + req.automatic, + undefined, + req.nativeGas, + ); + + const quote = await CircleTransfer.quoteTransfer(src.chain, dst.chain, xfer.transfer); + console.log("Quote", quote); + + console.log("Starting Transfer"); + const srcTxids = await xfer.initiateTransfer(src.signer); + console.log(`Started Transfer: `, srcTxids); + + // Waiting for the attestation with a timeout + console.log("Waiting for Attestation"); + const attestIds = await xfer.fetchAttestation(60_000); + console.log(`Got Attestation: `, attestIds); + + // Completing the transfer on the destination chain + console.log("Completing Transfer"); + const dstTxids = await xfer.completeTransfer(dst.signer); + console.log(`Completed Transfer: `, dstTxids); + + } catch (error) { + console.error("Error during CCTP transfer:", error); + // Additional guidance for troubleshooting + console.error("Make sure the chains are correctly configured and the amount is sufficient to cover fees."); + } +} + // Note, if the transfer is requested to be Automatic, a fee for performing the relay // will be present in the quote. The fee comes out of the amount requested to be sent. diff --git a/examples/src/tokenBridge.ts b/examples/src/tokenBridge.ts index 5c2de84e2..7e292a42e 100644 --- a/examples/src/tokenBridge.ts +++ b/examples/src/tokenBridge.ts @@ -96,6 +96,7 @@ import { getSigner, waitLog } from "./helpers/index.js"; console.log(receipt); })(); +// Enhanced error handling in tokenTransfer function async function tokenTransfer( wh: Wormhole, route: { @@ -111,57 +112,62 @@ async function tokenTransfer( }, roundTrip?: boolean, ): Promise> { - // EXAMPLE_TOKEN_TRANSFER - // Create a TokenTransfer object to track the state of the transfer over time - const xfer = await wh.tokenTransfer( - route.token, - route.amount, - route.source.address, - route.destination.address, - route.delivery?.automatic ?? false, - route.payload, - route.delivery?.nativeGas, - ); - - const quote = await TokenTransfer.quoteTransfer( - wh, - route.source.chain, - route.destination.chain, - xfer.transfer, - ); - console.log(quote); - - if (xfer.transfer.automatic && quote.destinationToken.amount < 0) - throw "The amount requested is too low to cover the fee and any native gas requested."; - - // 1) Submit the transactions to the source chain, passing a signer to sign any txns - console.log("Starting transfer"); - const srcTxids = await xfer.initiateTransfer(route.source.signer); - console.log(`Started transfer: `, srcTxids); - - // If automatic, we're done - if (route.delivery?.automatic) return xfer; - - // 2) Wait for the VAA to be signed and ready (not required for auto transfer) - console.log("Getting Attestation"); - const attestIds = await xfer.fetchAttestation(60_000); - console.log(`Got Attestation: `, attestIds); - - // 3) Redeem the VAA on the dest chain - console.log("Completing Transfer"); - const destTxids = await xfer.completeTransfer(route.destination.signer); - console.log(`Completed Transfer: `, destTxids); - // EXAMPLE_TOKEN_TRANSFER - - // If no need to send back, dip - if (!roundTrip) return xfer; - - const { destinationToken: token } = quote; - return await tokenTransfer(wh, { - ...route, - token: token.token, - amount: token.amount, - source: route.destination, - destination: route.source, - }); + try { + // Create a TokenTransfer object to track the state of the transfer over time + const xfer = await wh.tokenTransfer( + route.token, + route.amount, + route.source.address, + route.destination.address, + route.delivery?.automatic ?? false, + route.payload, + route.delivery?.nativeGas, + ); + + const quote = await TokenTransfer.quoteTransfer( + wh, + route.source.chain, + route.destination.chain, + xfer.transfer, + ); + console.log(quote); + + if (xfer.transfer.automatic && quote.destinationToken.amount < 0) { + throw new Error("The amount requested is too low to cover the fee and any native gas requested."); + } + + // 1) Submit the transactions to the source chain, passing a signer to sign any txns + console.log("Starting transfer"); + const srcTxids = await xfer.initiateTransfer(route.source.signer); + console.log(`Started transfer: `, srcTxids); + + // If automatic, we're done + if (route.delivery?.automatic) return xfer; + + // 2) Wait for the VAA to be signed and ready (not required for auto transfer) + console.log("Getting Attestation"); + const attestIds = await xfer.fetchAttestation(60_000); + console.log(`Got Attestation: `, attestIds); + + // 3) Redeem the VAA on the dest chain + console.log("Completing Transfer"); + const destTxids = await xfer.completeTransfer(route.destination.signer); + console.log(`Completed Transfer: `, destTxids); + + // If no need to send back, dip + if (!roundTrip) return xfer; + + const { destinationToken: token } = quote; + return await tokenTransfer(wh, { + ...route, + token: token.token, + amount: token.amount, + source: route.destination, + destination: route.source, + }); + } catch (error) { + console.error("Error during token transfer:", error); + // Provide additional guidance for troubleshooting + console.error("Ensure the token is supported on both chains and that the transfer amount covers all fees."); + } }