metaplex-foundation / Solana.Swift

This is a open source library on pure swift for Solana protocol.
MIT License
160 stars 75 forks source link

Implement Anchor #83

Closed ajamaica closed 1 year ago

ajamaica commented 3 years ago

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

littlejohntj commented 3 years ago

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

ajamaica commented 3 years ago

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

technoplato commented 3 years ago

@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],
  );
}
ajamaica commented 3 years ago

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

fatihhkuru commented 2 years ago

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

fatihhkuru commented 2 years ago

is it possible to make anchor client from idl?

j-h-a commented 2 years ago

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 commented 2 years ago

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.

ajamaica commented 1 year ago

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