Skip to content

Instantly share code, notes, and snippets.

View zikyfranky's full-sized avatar
🎯
Focusing

Isaac Frank zikyfranky

🎯
Focusing
View GitHub Profile
@zikyfranky
zikyfranky / Solana View Function.ts
Created April 16, 2024 10:38
This is a snippet to have anchor view function not trigger wallet confirmation
async readOnly(instruction: TransactionInstruction, instructionName: string): Promise<{ value: any }> {
// Filter through your IDL to get the actual read instruction schema and return type
const ixx = IDL.instructions.find((i) => i.name == instructionName);
// This checks if the instruction contains Mutable account, if it does, then it isn't a read only instruction
const isMut = ixx && [...ixx.accounts].find((a: any) => a.isMut);
const returnType = ixx && (ixx as any).returns;
if (isMut || !returnType) return { value: null }; // basically return null value if ix is mutable or it doesn't contain a return type
import random
print('''
This Code was created by Isaac Frank..
You can contact him on::
===============================================
Facebook: http://facebook.com/zikyfranky
===============================================
Twitter: http//twitter.com/zikyfranky
===============================================