Coder Social home page Coder Social logo

solana-php-sdk's People

Contributors

comradepashka avatar exzachlyvv avatar gabrielkoerich avatar hnassr avatar mattstauffer avatar miguilimzero avatar neverything avatar slawomir-pryczek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solana-php-sdk's Issues

Fatal error when insufficient funds

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?

How to get NFT token metadata by mint?

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)
image

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

image

Could you please help me to understand what is wrong here?

How to get owner of a token

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

Future of this repository?

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.

Getting NFT metadata

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

how to transfer tokens using this SDK i.e. spl-token transfer?

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]

Symfony 5.2 : A facade root has not been set

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.

Updating README.md to reflect 0.2.0 changes

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

  • Removing the Solana simple client part
  • Updating the code blocks and the text regarding the __call() method

When 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.

How to deal with rate limits of JSON RPC?

Hello,

I found documentation regarding limitations but couldn't find any information regarding proper rate limit controls.

image

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.

isOnCurve not right

isOnCurve not right

Base 58 Publickey:
q5xfHVuAsGmKRTmJNshERHHkVnHKxRX3cKzz5cYnFRn

It show return true for isOnCurve function. But false returned

getAccountInfo() does not properly handle a missing account.

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.

Bug? ProgramAddress is wrong

This morning I ran into an issue with PublicKey::findProgramAddress(). When I try to get the proper address for https://solscan.io/token/ApqMgGY9sbseui4QKoerDui61PbUADD1CfZZGWC6eWF5

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.

Change namespace and re-release on packagist

As mentioned in #36 (comment), we will change the namespace to Verze and re-release this package on packagist.

  • Update namespace
  • Update tests
  • Update documentation
  • Update roadmap
  • Check with Tighten to remove the old package
  • Release new version of the package

Any help with this is greatly appreciated as my time is a bit limited currently.

Invalid metadata address

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();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.