Solana: How to call the shared_accounts_route instruction on Jupiter?

Routing Instructions for Shared Accounts in Solana

Solana is a popular blockchain platform known for its fast and scalable transactions, making it an ideal choice for a variety of use cases, including decentralized finance (DeFi) and yield farming. One of the most commonly used directives in DeFi applications is the
swap instruction, which allows users to exchange one asset for another. However, getting these instructions on a Solana node in Jupiter, which hosts DeFi protocols, can be difficult due to the lack of SDKs.

Issue with Solana’s No-SDK Policy

In 2021, Raydium, a popular DeFi platform, announced that it would no longer provide a software development kit (SDK) for Solana. This decision left many developers with the challenge of using Jupiter, one of the few nodes hosting Solana’s DeFi protocol, without the SDK.

Solution: Using a third-party library or manual implementation

In this article, we will explore two possible solutions to call the share_accounts_route directive in Jupiter:

1. Using a third-party library

One solution is to use a third-party library that provides a function that calls Solana’s share_accounts_route directive. These libraries can be used by developers who do not have access to the SDK.

A popular example of a library that supports the share_accounts_route directive is
solana-programmatic-sdk. You can install this library using npm or thread:

npm install solana-programmatic-sdk

After installation, you can import the library and call the share_accounts_route directive with its functions.

2. Manual implementation

Another way is to manually enable the share_accounts_route directive in Solana. This requires some knowledge of the Solana programming language (Solana Script) and the
jupiter-SDK library, which provides a set of APIs to interact with the Jupiter node.

Here is an example of how to call share_accounts_route using a manual implementation:

import { Web3 } from @solana/web3.js;

const web3 = new Web3();

async function callSharedAccountsRoute(amount: string, recipientAddress: string) {

const params = [

'shared_accounts_route',

0x${amount}',

0x${recipientAddress},

];

try {

const result = await web3.publickeyAtIndex(

[params.join('|')],

web3PubKey.atIndex(params[0])

);

console.log(result);

} catch(error) {

console.error(error);

}

}

// Example usage:

callSharedAccountsRoute('1', '0x...'); // Replace recipient with address

Conclusion

Solana: How to call the shared_accounts_route instruction on Jupiter?

Calling shared_accounts_route on Jupiter can be difficult due to the lack of SDK. However, using a third-party library or a manual implementation offers two viable solutions for developers who need access to these instructions. By following the examples provided in this article, you should be able to call shared_accounts_route and interact with your Solana application.

Note

: Before implementing the solution, make sure to follow the terms of service and user manual of the Jupiter node hosting Solana’s DeFi protocol.

ethereum would understand mining

类似文章

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注