Solana: How to call the shared_accounts_route instruction on Jupiter?

How to Call a Shared Accounts Route Instruction on Solana

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

The Problem 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 facing the challenge of using Jupiter, which is one of the few nodes hosting DeFi protocols on Solana, without an SDK.

The Solution: Using a Third-Party Library or Manual Implementation

In this article, we will explore two possible solutions to call the shared_accounts_route instruction on Jupiter:

1. Using a Third-Party Library

One approach is to use a third-party library that provides a function to call the shared_accounts_route instruction on Solana. These libraries can be used by developers who do not have access to a SDK.

A popular example of a library that supports the shared_accounts_route instruction is
solana-programmatic-sdk

Solana: How to call the shared_accounts_route instruction on Jupiter?

. You can install this library using npm or yarn:

npm install solana-programmatic-sdk

Once installed, you can import the library and use its functions to call the shared_accounts_route instruction.

2. Manual Implementation

Another approach is to manually implement the shared_accounts_route instruction on Solana. This requires some knowledge of the Solana programming language (Solana Script) and the
jupiter-SDK library, which provides a set of APIs for interacting with the Jupiter node.

Here’s an example of how you can call the shared_accounts_route instruction using 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 with the recipient address

Conclusion

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

Note: Before implementing any solution, ensure that you comply with the terms of service and usage guidelines for the Jupiter node hosting DeFi protocols on Solana.

Ethical Guidelines for AI in the Cryptocurrency Ecosystem

The Best Practices for Storing and Using Your Crypto Card

Ethereum: What happens to Bitcoin wallet / Bitcoins if PC is stolen

Limit order, Fork, ApeCoin (APE)

Ethereum: How do I find the exchange an address belongs to

Metamask: Is it possible to validate the Metamask personal_sign in the back end?