可能交换溶胶与USDC吗?

发布于 2025-02-10 03:30:13 字数 1410 浏览 2 评论 0原文

我正在尝试将SOL转换为USDC,这是我尝试使用Web3J,Raydium甚至木星尝试的,这些集成都没有返回积极的结果,另一方面,我没有找到有关该主题的文档,我知道如何发送令牌 - >令牌但没有加密(sol) - > 稳定的折磨(USDC)

我要做的是

现在要与木星一起工作,这是不可能的,有没有办法在SOL和USDC之间进行交换?代码示例

const jupiter = await Jupiter.load({
            connection: this.connection,
            cluster: "mainnet-beta",
            user: wallet,
        });

        const tokens = await this.getTokens();

        console.log(tokens);


        const routeMap: Map<string, string[]> = jupiter.getRouteMap();
        const outputToken = tokens.find((t) => t.address == "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
        const inputToken = tokens.find((t) => t.address == environment.swap.WrappedSolAddress);

        const routes = await jupiter.computeRoutes({
            inputMint: new PublicKey(inputToken.address),
            outputMint: new PublicKey(outputToken.address),
            inputAmount: LAMPORTS_PER_SOL * 1,
            slippage: 1,
        });

        const { execute } = await jupiter.exchange({
            routeInfo: routes.routesInfos[0],
        });

        const swapResult: any = await execute();

错误

TypeError: Cannot read properties of undefined (reading 'address')
at SolanaService.<anonymous> (/home/foo/GitHub/foo/dist/apps/foo/webpack:/doo/apps/foo-api/src/app/services/solana/solana.service.ts:208:55)

I am trying to SWAP from SOL to USDC, this is what I have tried with web3js, Raydium and even Jupiter, none of these integrations have returned a positive result, on the other hand I do not find much documentation on the subject, I know how to send TOKEN -> TOKEN but no CRYPTO (SOL) -> STABLE-COIN (USDC)

What I am trying to do is make the SWAP work now with Jupiter, this has been impossible, there is a way to make SWAP between SOL and USDC?

Code Example

const jupiter = await Jupiter.load({
            connection: this.connection,
            cluster: "mainnet-beta",
            user: wallet,
        });

        const tokens = await this.getTokens();

        console.log(tokens);


        const routeMap: Map<string, string[]> = jupiter.getRouteMap();
        const outputToken = tokens.find((t) => t.address == "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
        const inputToken = tokens.find((t) => t.address == environment.swap.WrappedSolAddress);

        const routes = await jupiter.computeRoutes({
            inputMint: new PublicKey(inputToken.address),
            outputMint: new PublicKey(outputToken.address),
            inputAmount: LAMPORTS_PER_SOL * 1,
            slippage: 1,
        });

        const { execute } = await jupiter.exchange({
            routeInfo: routes.routesInfos[0],
        });

        const swapResult: any = await execute();

Error

TypeError: Cannot read properties of undefined (reading 'address')
at SolanaService.<anonymous> (/home/foo/GitHub/foo/dist/apps/foo/webpack:/doo/apps/foo-api/src/app/services/solana/solana.service.ts:208:55)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞花火° 2025-02-17 03:30:13

您获取令牌的方式可能是错误的

import {Jupiter,TOKEN_LIST_URL} from "@jup-ag/core"

const tokens = await (await fetch(TOKEN_LIST_URL["devnet"])).json();
console.log(tokens.find((t)=> t.address == "7duMWSNdYMof6WKZHs5X1wdmmxUa6cDGqqKShhMSGkgg"))

The way you're fetching tokens might be wrong

import {Jupiter,TOKEN_LIST_URL} from "@jup-ag/core"

const tokens = await (await fetch(TOKEN_LIST_URL["devnet"])).json();
console.log(tokens.find((t)=> t.address == "7duMWSNdYMof6WKZHs5X1wdmmxUa6cDGqqKShhMSGkgg"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文