metaplex-foundation / solana.swift Goto Github PK
View Code? Open in Web Editor NEWThis is a open source library on pure swift for Solana protocol.
License: MIT License
This is a open source library on pure swift for Solana protocol.
License: MIT License
Describe the bug
Error Retrieving Account information
To Reproduce
Steps to reproduce the behavior:
let network = NetworkingRouter(endpoint: .mainnetBetaSolana)
solana = Solana(router: network, accountStorage: accoutStorage)
// Entered valid phrase for testing
let account = Account(phrase: ["my", "phrase"], network: .mainnetBeta, derivablePath: nil)
accoutStorage.save(account!)
solana.api.getAccountInfo(account: account!.publicKey.base58EncodedString, decodedTo: AccountInfo.self) {
switch $0 {
case .success(let info):
print(info)
case .failure(let error):
print(error)
/*
value is null
request(method:bcMethod:parameters:onComplete:) -> {\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":112043777},\"value\":null},\"id\":\"17BBD8D5-7A01-4C72-9049-203894E719AA\"}\n"
*/
}
}
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
iOS
Smartphone (please complete the following information):
iPhone Simulator
Additional context
Add any other context about the problem here.
The system program address in PublicKey
is exposed as simply programId
.
This is confusing, especially given that programId
appears in so many other places, meaning different program ids.
I suggest adding systemProgramId
with the same value and marking programId
as deprecated like this:
@available(*, deprecated, renamed: "systemProgramId")
static let programId = PublicKey(string: "11111111111111111111111111111111")!
static let systemProgramId = PublicKey(string: "11111111111111111111111111111111")!
Xcode will generate a fix-it automatically with this method of deprecation, so it is easy for users to change.
I want to get info about transaction and use func getConfirmedTransaction(transactionSignature: String, onComplete: @escaping (Result<TransactionInfo, Error>) -> Void)
But I can't get info about transaction, because it's not public. Is it possible to make it public or should I use another func to get transaction info?
Hi, first of all thanks for this great library.
I'm trying to use sendSPLTokens to transfer custom token to another wallet address, and I'm a bit stuck on what it means by fromPublicKey
and destinationAddress
I tried either wallet address and token account address for fromPublicKey
, but I got the below error
Transaction simulation failed: Attempt to debit an account but found no record of a prior credit
extension Action {
public func sendSPLTokens(
mintAddress: String,
from fromPublicKey: String,
to destinationAddress: String,
amount: UInt64,
allowUnfundedRecipient: Bool = false,
onComplete: @escaping (Result<TransactionID, Error>) -> Void
In web3.js I can understand that the from
and to
refer to the token account address, not the wallet.
splToken.Token.createTransferInstruction(
splToken.TOKEN_PROGRAM_ID,
fromTokenAccount.address,
toTokenAccount.address,
fromWallet.publicKey,
[],
0
)
I'm using testnet and my wallet has enough custom token https://explorer.solana.com/address/BPkzsoetXHfH228V8B74xpZC22SNVgu3NX8hiwNPbEpH?cluster=testnet
I know this is not really an issue with the library, but how to correctly use this method.
Thanks, any help is appreciated π
It's currently not possible to send custom transactions to your own Solana program with this package as-is.
TransactionInstruction
does not have a public init
which means you can't create and send one from outside the package.
Longer term it may be desirable to have full Anchor support, but in the mean-time (and for programs that don't use Anchor) it would be useful to be able to create and send custom instructions.
#83 discusses a possible way to do this by creating a TransactionInstruction
and then sending it with solana.action.serializeAndSendWithFee
- however, without a public initialiser this isn't actually possible from outside.
It would be good to discuss the options, a public init would be the simplest, but it may also be desirable to have static helpers like createCustomInstruction
which could be made generic and specialised on a CustomInstruction
interface, allowing external code to implement custom instructions and then create/send them. Has this been thought about much?
Describe the bug
When trying to use this package in swift I get the above error. To fix this there should be a package for both x86 and arm64.
func testTransactionDecode() {
let swapTransaction = "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAsTL5MjcP0ElSKS7nWnvOk+qZvJ6jITGFotkuy1gKFqIhsLSAdPdbjqMGnJ7T8GvDIZeCrkzY5cnTdJglaxmEudUCHtjI0soEUFAsQ3TdZgefXZpm+TSpDt0GSupo6DANLCL9p3EN7QVm+wCbiCUn2jVyJyazsZQYgqVRhf6h2a/pVY72d/tWNeZHNyS3Dha2QFVANOpHocez/NiIU8QV0yVF04h3XRAtqKdDmTPAd8xoLiu/N2FBWd4n6ilf8Yhj5ycgN6mCDYmBgfgSLDzFZMCMkNJi8513JLWWbMZSdwwSnCib7PSSoSILtrVDwUD5nwX+E/CqiYjJF6S312CKXScwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAEedVb8jHAbu50xW7OaBUH/bGy3qP0jlECsc2iVrwTjwXQ6k8zc3ATpWPgk0jttvRZPZH8dkH5JHwkQahCobvrBpuIV/6rgYT7aH9jRhjANdrEOdwa6ztVmKDwAAAAAAEG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqTq4kD+3NcqxxnxZr0hX7fYbCvgypQp8WeMhkZ4OyKm8Yahhc3zJAYwffkWR86hkxsihTWzLBM1l7HhE4D472TKMlyWPTiSJ8bs9ECkUjg2DC1oTmdr/EIQEjnvY2+n4WbQ/+if11/ZKdMCbHylYed5LCas238ndUUsyGqezjOXoxvp6877brTo9ZfNqq8l0MbG75MLS9uDkfKYCA0UvXWFmjY92JM6L+n8NG0oowIrwOhILCaj2T4l5EfleAO8P/QcJAAUC2oUCAAkACQPoHwAAAAAAABAGAAUADAgNAQEIAgAFDAIAAACAlpgAAAAAAA0BBQERChYNDgAFBAEHDBIKChEKCw8DDgQBBgINJcEgmzNB1pyBBAEAAAAcAWQAAYCWmAAAAAAA3OYOAAAAAAAyAAANAwUAAAEJ"
let data = Data(base64Encoded: swapTransaction)
assert(data != nil)
let transaction = try! Transaction.from(buffer: data!)
print(transaction)
}
Is your feature request related to a problem? Please describe.
Allow clients to batch rpc request of operation for parallel request.
Describe the solution you'd like
Allow the Router to ship more than one RPC request and return array of results. Not sure if I should limit them to N so we dont kill the rpc or get banned. Maybe thats developer responsability
Is your feature request related to a problem? Please describe.
There is no need to set the Account cluster. It is not used for anything
Describe the solution you'd like
Remove the cluster from the account
I am using this library for solana spl token transfer. I can successfully created token account for sender but not able to create token account for receiver. As i have no secret key of receiver so how can i create token account for receiver can anyone help please?
RPCEndpoint is using the wrong url of testnet api in the definition of its static property .testnetSolana. If using this in the initiation of a NetworkRouter and call RPC APIs will end up with a network error.
It should be
RPCEndpoint(url: URL(string: "https://api.testnet.solana.com")!, urlWebSocket: URL(string: "wss://api.testnet.solana.com")!, network: .testnet)
instead of
RPCEndpoint(url: URL(string: "https://testnet.solana.com")!, urlWebSocket: URL(string: "wss://testnet.solana.com")!, network: .testnet)
Solana.Swift now supports partial signing, but when the transaction is serialized, the space for null signatures is not being reserved, causing the signature to be trimmed off entirely when the transaction is deserialized.
When calling getTokenWallets()
it returns with an array of Wallets.
My understand is if the wallets' token is not supported, the Token parameter of the returning Wallet will only contain an address.
Maybe adding some option to config to fetch more data of the token, like name, logo, and even attributes for NFTs.
Or is there a function that already meets the needs?
Thank you. This library really helps a lot
Describe the bug
Attempting to build a project that has Solana.swift as a dependency in SPM fails to build with a linker error, Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport
To Reproduce
Steps to reproduce the behavior:
Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport
Expected behavior
The project should build
Is your feature request related to a problem? Please describe.
We'd like to use partial signing to add a remote feePayer to transactions on iOS.
Describe the solution you'd like
A public, standalone version of Transaction.partialSign is required to support remote signing.
Additional context
This already exists on solana-web3.js, see implementation here: https://github.com/solana-labs/solana-web3.js/blob/13cd6f5/src/transaction.ts#L494:L525
Currently the Solana.Swift lib has the same internal "_partialSign" function as JS, but it's missing the public wrapper.
https://github.com/ajamaica/Solana.Swift/blob/master/Sources/Solana/Models/SendingTransaction/Transaction.swift#L76
Use a networking module so we can inject url session an configure endpoint and retry
Is your feature request related to a problem? Please describe.
Result builders (a big part of the transaction template structures we discussed) require a bump to Swift 5.4. Though 5.5 has features that require specific iOS versions, I believe Swift 5.4 is entirely backwards compatible. As version bumps go, this one may be pretty innocuous.
Describe the solution you'd like
Bumping requirements in the package to Swift 5.4, amending Github workflows to support it, and updating the documentation.
Describe alternatives you've considered
An alternative would be to use either chained struct mutations (similar to Solnet's builders) or
Additional context
I've gotten Swift 5.4 working on GitHub actions before βΒ it's not too bad.
Hello Arturo!
I was trying findSPLTokenDestinationAddress and it didn't seem to work, I went into the source code and discovered this for-loop in findProgramAddress
:
for nonce in stride(from: UInt8(255), to: 0, by: -1) {
let seedsWithNonce = seeds + [Data([nonce])]
return createProgramAddress(
seeds: seedsWithNonce,
programId: programId
).map {($0, nonce) }
}
Is everything okay here? It returns on the first iteration of the loop.
If not, is the following code correct?
for nonce in stride(from: UInt8(255), to: 0, by: -1) {
let seedsWithNonce = seeds + [Data([nonce])]
let programAddressResult = createProgramAddress(seeds: seedsWithNonce, programId: programId)
if case .success(let publicKey) = programAddressResult {
return .success((publicKey, nonce))
}
}
Thanks
Is there a way to wait for a transaction to be finalized before continuing to the next thing? This is really helpful to show a loading state to the user until we know the result of their action.
Describe the bug
Expected behavior
All of these should be public. In both the solana-web3.js implementation and the SolanaKT implementation these are acessible, so the standard is already set to expose these.
Is your feature request related to a problem? Please describe.
Parse tokens from the official list instead of the current list.
Describe the bug
I'm currently using MW to create unsigned transactions, return to frontend, serialize and sign. After signing and sending the transaction I'm getting "Signature Verification Failed" error from the chain.
I'm using serialize function with requiredAllSignatures and verifySignatures parameters as true and getting no error. However, when sending on-chain this error occurs. When I checked the serialized data created for same transaction on web3.js and Solana.Swift library there were some differences in UInt8 array.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Transaction should go through and be successful on chain.
@ajamaica I am using Solana Swift Package Dependency in my project and using some model classes from your summer wallet demo. But while running the CICD workflow ( GitHub actions ) in the build archive section getting the error error: no such module 'Solana' in the Summer Wallet Model classes. I have also attached the screenshot regarding that. (It's working in manual archive from Xcode.) I have also added clean and build command in the CICD workflow so can fetch this Package Dependency.
I am fixing this error since many days but not getting success so please I would like your help.
Hi how can i receive token metadata like symbol, icon and name from dev net:
https://explorer.solana.com/address/Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr?cluster=devnet
the function i use is the following:
let accounts = try await connection!.action.getTokenWallets(account: account!.publicKey.description)
which gives me the balance yes but not metadata provided:
Solana.Wallet(pubkey: "5v1hgkjCSee7LqMmghNk4Rq6szmmzu78hPKfDNeprdnc", ammount: Optional(Solana.TokenAmount(amount: "2000000000", decimals: 6, uiAmount: 2000.0, uiAmountString: "2000")), token: Optional(Solana.Token(chainId: nil, address: "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr", symbol: nil, name: nil, logoURI: nil, extensions: nil, tags: Optional([]), isNative: false)), liquidity: Optional(false))
so how can i get this information:
symbol: nil, name: nil, logoURI: nil,
The tests are currently failing, and it appears some use the real NetworkingRouter
and actually talk to a GenesysGo devnet node.
This is undesirable for a number of reasons.
Fix is to implement a mock version of SolanaRouter
that provides appropriate responses for each test case.
Describe the bug
Do not relay on External info for spl information.
@ajamaica I am getting error in my created project like RXSolana module not found. Can you please share the dependency url or anything else which I can use for that?
Can the "findProgramAddress" function in the PublicKey extension be made public. It is currently private and therefore can't be used by applications to directly calculate Program Derived Addresses (PDA's).
File to update: Extensions / PublicKey / PublicKey+AssociatedTokenProgram.swift
Describe the bug
Action.sendSPLTokens always fails with a destination address of an original account address (the address of SOL account), no matter if there is an existing associated token address under the original account. The action only works when "to" and "from" are both associated token addresses other than their owners.
Expected behavior
If I did not get the design intention wrong, the action should check if the destination passing in is an associated token address or an original address. If it is an original address, the program will find its associated token address registered under the mint, or create a new one if not existing. However I'm getting errors under both conditions.
I'm using the mint address of USDC in my tests on testnet: CpMah17kQEL2wqyMKt3mZBdTnZbkbfx4nqmQMFDP5vwp
I have utilized this package dependency for Solana integration and used version 2.0.2 for Solana's flow. Unfortunately, I am encountering the following error in Xcode 15:
Type 'SolanaSocket' does not conform to the 'WebSocketDelegate' protocol.
There is already a WebSocketDelegate method within the SolanaSocket extension, but I am still getting this error, and I am unable to edit the file due to the package dependency.
It would be great if you could assist me with this?
Not sure if I am missing some documentation around this, if I am please point me to the right place.
I need to implement some features to the app I am building, I have managed to use Metaplex Solana.Swift HotAccount to create a wallet, and use its public key to retrieve NFTs. I have not managed to use a private key to, say, retrieve the account mnemonic phrase. Are these functions not available? If not, what should I be using?
I can see that there is a function called "SendSol". It seems to take in an account object presumably attached with private key? How does this process work? Where is the documentation I can use to investigate?
I use BitcoinKit, BitcoinCore who have switched to using https://github.com/GigaBitcoin/secp256k1.swift.git. To prevent conflicts, could you make this transition?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.