Solana.Swift icon indicating copy to clipboard operation
Solana.Swift copied to clipboard

Implement Anchor

Open ajamaica opened this issue 3 years ago • 8 comments

https://github.com/project-serum/anchor

ajamaica avatar Jun 28 '21 13:06 ajamaica

does this imply that Solana.swift won't currently work with an anchor app?

littlejohntj avatar Sep 11 '21 04:09 littlejohntj

It will work but won't generate a client. This library has all the buildings blocks

ajamaica avatar Sep 11 '21 17:09 ajamaica

@ajamaica Thanks for your work here everything is very helpful and easy to get up and running.

As far as sending a TransactionInstruction to the hello world application from the Swift client, do you have any guidance? https://github.com/solana-labs/example-helloworld

EDIT

We want to specifically port this function to Swift, but we aren't sure how to construct the required arguments.

/**
 * Say hello
 */
export async function sayHello(): Promise<void> {
  console.log('Saying hello to', greetedPubkey.toBase58());
  const instruction = new TransactionInstruction({
    keys: [{pubkey: greetedPubkey, isSigner: false, isWritable: true}],
    programId,
    data: Buffer.alloc(0), // All instructions are hellos
  });
  await sendAndConfirmTransaction(
    connection,
    new Transaction().add(instruction),
    [payer],
  );
}

technoplato avatar Sep 11 '21 18:09 technoplato

it will translate something like this.

let network = NetworkingRouter(endpoint: .devnetSolana)
let solana = Solana(router: network, accountStorage: self.accountStorage)
let instruction = TransactionInstruction(
            keys: [
                .init(publicKey: greetedPubkey, isSigner: false, isWritable: true),
            ],
            programId: programId,
            data: [0]
 )

solana.action.serializeAndSendWithFee(instructions: [instruction], signers: [payer]) { // doSomethingWithResponse() }

I dont know the type of the 0 so I assume is a u8

Edited to match your edit

ajamaica avatar Sep 12 '21 04:09 ajamaica

Does anyone know about how to genereate anchor client for swift?

fatihhkuru avatar Dec 11 '21 13:12 fatihhkuru

is it possible to make anchor client from idl?

fatihhkuru avatar Dec 11 '21 13:12 fatihhkuru

#150 doesn't fix this entire "implement Anchor" but it's a start. And probably enough tbh. If you want to send instructions to your anchor program it does the job...

j-h-a avatar Feb 04 '22 07:02 j-h-a

Is there still any interest in supporting anchor contracts? There have been no comments on #150 (which I created as draft specifically to garner comments/feedback on the approach) so I'm not really sure how to progress it. I was hoping it could be the first step in an incremental approach to more complete support, but if there's no community interest then I'll just focus on what we need instead.

j-h-a avatar Apr 08 '22 19:04 j-h-a

This is now done here https://github.com/metaplex-foundation/solita-swift

ajamaica avatar Oct 21 '22 18:10 ajamaica