verze-app / solana-php-sdk Goto Github PK
View Code? Open in Web Editor NEWSimple PHP SDK for Solana JSON RPC endpoints
License: MIT License
Simple PHP SDK for Solana JSON RPC endpoints
License: MIT License
Hello,
I found documentation regarding limitations but couldn't find any information regarding proper rate limit controls.
https://docs.solana.com/cluster/rpc-endpoints#mainnet-beta
Normally I would expect some header to tell me regarding my quota information to be able to sleep my code for some time but I was able to only get HTTP 429 after I got an error and then retry failed requests which is not the most efficient approach. I am wondering if you figured out already some solution for this problem.
Hello!
How to generate a recovery passphrase?
Using https://github.com/metaplex-foundation/metaplex/blob/master/ARCHITECTURE.md#token-metadata-contract as a base, I'll try and implement this in my project.
Hello,
I am super happy to discover this repository and appreciate what you do here.
I checked previous issues and found past discussions regarding metadata, but unfortunately, I couldn't make it work.
Mint is 4EbYVzfS5ad5wYcAdoaxJM7HUeiQq9RnCeSm289CUcC6 (I also tried with 3k7M6KoYQ8kkpcWqceAZokLJHfiVfHGNtU7an5BGPh3C)
I am trying to get metadata with the following code
$METADATA_PUBKEY = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
/** @var PublicKey $pda */
list($pda, $bump) = PublicKey::findProgramAddress([
'metadata',
$METADATA_PUBKEY,
(new PublicKey('4EbYVzfS5ad5wYcAdoaxJM7HUeiQq9RnCeSm289CUcC6')),
], $METADATA_PUBKEY);
Metadata::fromBuffer($pda->toBuffer()->toArray());
But it is throwing the following error
Tighten\SolanaPhpSdk\Borsh\BorshException: Expected buffer length 32 isn't within bounds in file /Users/farid/projects/web3/vendor/tightenco/solana-php-sdk/src/Borsh/BinaryReader.php on line 177
I also checked this token on Solscan and it looks correct. Not sure if I am using the correct id.
https://solscan.io/token/4EbYVzfS5ad5wYcAdoaxJM7HUeiQq9RnCeSm289CUcC6#metadata
Could you please help me to understand what is wrong here?
Hey @mattstauffer, I just saw that you deprecated the package. As I'm still using it on a project, I would love to take it over.
Are any of you interested in taking it over with me?
@faridmovsumov, @pantaovay, others?
Turns out there's a PHP client for ETH:
https://twitter.com/jack_clancy93/status/1436515655201792006
https://github.com/web3p/web3.php
Might be worth learning from once this is basically built out. But I'm gonna worry about that later.
I wanted to update the README.md
file to reflect the breaking changes in 0.2.0, but I'm not sure what the best way is to update the following portion: https://github.com/tighten/solana-php-sdk/blob/main/README.md?plain=1#L20-L42
Solana
simple client part__call()
methodWhen trying to use:
$sdk = new Program(new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT));
$accountInfo = $sdk->getAccountInfo('4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA');
var_dump($accountInfo);
It throws an error, which makes sense:
TypeError
Tighten\SolanaPhpSdk\SolanaRpcClient::call(): Argument #2 ($params) must be of type array, string given, called in /Users/neverything/Sites/.../vendor/tightenco/solana-php-sdk/src/Program.php on line 19
Not sure if the intention is to use the classes individually like so @exzachlyvv and @mattstauffer?
$sdk = new Connection(new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT));
$accountInfo = $sdk->getAccountInfo('4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA');
var_dump($accountInfo);
Let me know how I can assist with updating the docs accordingly.
What would this mean?
Would love to help out
Hello!
I'm trying to retrieve metadata from an NFT using the code sample in #22. It's working pretty well but for some NFTs the metadata address retrieve by findProgramAddress is'nt the good one.
Example :
Mint: 887sH18E7pkUco4zfUFZxiXAEsgCVRd6vNX5HaT9CSmC
Expected metadata address: 8HXWP5BQ83riaGdYofKqcKLkbgeusy6efNc4E6ZDHj6s
Metadata generated: 7C8w6HC1bMqDMV6nC9Krmz7qV1eTutmsprb57F1nx6Xd
$metaplex = new PublicKey(MetaplexProgram::METAPLEX_PROGRAM_ID);
list($pda, $bump) = PublicKey::findProgramAddress(['metadata', $metaplex, (new PublicKey($mint))], $metaplex);
$address = $pda->getPublicKey()->toBase58();
Hey @exzachlyvv and @mattstauffer thank you so much for putting in so much effort to make this available in PHP.
Using the @exzachlyvv fork created, I'm trying to rebuild something like this https://www.vicyyn.com/#/nft?DqGGFuiWRiJ6Mim1qafLWn6FZzBGGcSTyFFSJ8RpuqE8
The code used on the site above is: https://github.com/vicyyn/MetaplexMetadata-js
It somehow espaces me how to use the PublicKey::findProgramAddress
compared to the one in the repo above. I can't seem to get the seed part working properly.
Any hint would be greatly appreciated
Hello,
I have an error with my Symfony 5.2 :
throw new RuntimeException('A facade root has not been set.');
in illuminate\support\Facades\Facade.php (line 258).
How can I fixe it please ?
Regards.
The library currently do not support to set timeout parameter.
Hello, I would like to ask if anyone used this SDK to mint collection to solana, I was wondering the same for NFT? Also can you navigate me where I can find the documentation about this SDK. Thank you in advance.
Hi all!
I got error when insufficient funds: Fatal error: Uncaught Tighten\SolanaPhpSdk\Exceptions\GenericException: Transaction simulation failed: Transaction results in an account (1) without insufficient funds for rent in /var/www/www-root/data/www/site.com/vendor/tightenco/solana-php-sdk/src/SolanaRpcClient.php:106 Stack trace: #0 /var/www/www-root/data/www/site.com/vendor/tightenco/solana-php-sdk/src/SolanaRpcClient.php(68): Tighten\SolanaPhpSdk\SolanaRpcClient->validateResponse(Object(Illuminate\Http\Client\Response), 'sendTransaction', Array) #1 /var/www/www-root/data/www/site.com/vendor/tightenco/solana-php-sdk/src/Connection.php(86): Tighten\SolanaPhpSdk\SolanaRpcClient->call('sendTransaction', Array) #2 /var/www/www-root/data/www/site.com/core/ajax/withdraw.php(63): Tighten\SolanaPhpSdk\Connection->sendTransaction(Object(Tighten\SolanaPhpSdk\Transaction), Array) #3 {main} thrown in /var/www/www-root/data/www/site.com/vendor/tightenco/solana-php-sdk/src/SolanaRpcClient.php on line 106
Why is a Fatal error produced and how to fix it?
As mentioned in #36 (comment), we will change the namespace to Verze
and re-release this package on packagist.
Any help with this is greatly appreciated as my time is a bit limited currently.
Hello,
I used the function getTokenLargestAccounts to get the Token account (address), but from here i would like to get the owner wallet.
Is there a way I can accomplish that?
Thank you
This morning I ran into an issue with PublicKey::findProgramAddress()
. When I try to get the proper address for https://solscan.io/token/ApqMgGY9sbseui4QKoerDui61PbUADD1CfZZGWC6eWF5
9ajTce3dAtFaG6jJrNPq9vBVW4mwWDgmPqbZybvZYrzj
, nonce 255
5zhP1LiHVw6rgZRRWqzV6Vh97RBJM7kZ9i3HjtynKu6S
, nonce 254
In order to quickly fix it in my job, I did the following:
protected function maybeGetMetaData() : array
{
while ($this->currentNonce != 0) {
$client = new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT);
$account = $client->call('getAccountInfo', [$this->programAddress, ["encoding" => "jsonParsed"]]);
if (! $this->hasEncodedMetaData($account)) {
$this->currentNonce--;
$this->canGetProgramAddress();
sleep(1);
continue;
}
return $account;
}
return [];
}
So basically as long as the getAccountInfo
call returns an array that is missing the Borsh data $this->canGetProgramAddress
is calling a custom version of findProgramAddress
that accepts the nonce as a third parameter.
/**
* @param array $seeds
* @param PublicKey $programId
* @param int $nonce
* @return array 2 elements, [0] = PublicKey, [1] = integer
* @throws BaseSolanaPhpSdkException
*/
static function findProgramAddress(array $seeds, PublicKey $programId, int $nonce = 255): array
{
while ($nonce != 0) {
try {
$copyOfSeedsWithNonce = $seeds;
array_push($copyOfSeedsWithNonce, [$nonce]);
$address = PublicKey::createProgramAddress($copyOfSeedsWithNonce, $programId);
} catch (\Exception $exception) {
$nonce--;
continue;
}
return [$address, $nonce];
}
throw new BaseSolanaPhpSdkException('Unable to find a viable program address nonce.');
}
Not very elegant and I have to rate limit the calls to the enpoints ๐ , but it does the trick for me.
not an issue but a question or a feature request
is it possible to transfer tokens using this SDK like with the Solana CLI using a terminal?
Terminal Example:
$spl-token transfer --allow-unfunded-recipient --fund-recipient [token address] [amount of tokens] [recipients wallet]
Hey @mattstauffer / Tighten!
What do you envision for this package? Do you want this to be the Solana library for the PHP ecosystem? If yes, I've been working on porting the Solana js library to PHP here.
I originally forked from this library. I'm happy to merge my work back in and we can use this repository. If we go that route, do you think I could get more ownership over this repo? It would be nice to be able to merge in my own PRs, at least upfront to get this off the ground.
Another route is I can start a new repo and that can take over as the Solana PHP SDK.
Don't want to step on any toes, down for whatever, I just want to make sure we can keep moving forward with a Solana SDK for PHP.
how do eth private key to sol address?
isOnCurve
not right
Base 58 Publickey:
q5xfHVuAsGmKRTmJNshERHHkVnHKxRX3cKzz5cYnFRn
It show return true
for isOnCurve
function. But false
returned
Right now, if you call the getAccountInfo({pubKey})
method where the {pubKey} does not exist, it will fail with error message:
TypeError: Tighten\SolanaPhpSdk\Solana::getAccountInfo(): Return value must be of type array, null returned
I propose that we check for this, and throw a new AccountNotFoundException.
When doing local Solana development. It is helpful to connect to a local solana-test-validator.
Let's add that endpoint as a const.
When i tried Borsh::serialize() i got this error..
Call to undefined method Tighten\\SolanaPhpSdk\\Borsh\\BinaryWriter::writeTighten\\SolanaPhpSdk\\Accounts\\Creator()
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.