Skip to content

How to use this? #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
poejanetwork opened this issue Jan 27, 2025 · 1 comment
Open

How to use this? #18

poejanetwork opened this issue Jan 27, 2025 · 1 comment

Comments

@poejanetwork
Copy link

poejanetwork commented Jan 27, 2025

I already composer it (composer require attestto/solana-php-sdk) and make a test PHP file

<?php

ini_set('display_errors', 'on');
require_once('sub_api/libs/solana-php-sdk/vendor/autoload.php');
use Attestto\SolanaPhpSdk\Connection;
use Attestto\SolanaPhpSdk\SolanaRpcClient;
// Using a defined method
$client = new SolanaRpcClient(SolanaRpcClient::DEVNET_ENDPOINT);
$connection = new Connection($client); // MAINNET_ENDPOINT
$accountInfo = $connection->getBalance('B7dwR8DSLzwEYzyPKtX5MHhoe2XzfvBHkP759Q5zzM4h');
$getBalance = $accountInfo/1000000000;
  echo "<pre>";
  print_r("balance = ". $getBalance);
  echo "</pre>";

$fromPublicKey = KeyPair::fromSecretKey(['nKsCgMmf9SPMKUFP6GgaSFik7W1BZyfWSGJqCF4itjdpbwiuxdqSsRvV6dzWZDXe7CdoHh5npS3D7v1Qjm6rAow']);
$toPublicKey = new PublicKey('2aGoKx41dPRU6L7HrX33Az6VdFU7C9u7qnE8yF56bqKA');
$instruction = SystemProgram::transfer(
    $fromPublicKey->getPublicKey(),
    $toPublicKey,
    1
);

$transaction = new Transaction(null, null, $fromPublicKey->getPublicKey());
$transaction->add($instruction);

$txHash = $connection->sendTransaction($transaction, $fromPublicKey);
echo "<pre>";
print_r($txHash);
echo "</pre>";

And got this result

10

Fatal error: Uncaught Error: Class "KeyPair" not found in C:\xampp\htdocs\pro.ject\sol.php:16 Stack trace: #0 {main} thrown in C:\xampp\htdocs\pro.ject\sol.php on line 16

Do I miss anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@poejanetwork and others