Skip to content

How to use this? #18

@poejanetwork

Description

@poejanetwork

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions