there's the following ETH JSONRPC implementation to transfer tokens, which can be utilised via curl in PHP and I would like to do EXACTLY the same but on the Solana Blockchain - which supports it's own JSONRPC implementation
var whatever= {};
whatever.jsonrpc="2.0";
whatever.id=1;
whatever.method="eth_sendTransaction";
whatever.params= [];
whatever.params[0].from="0x52f273a06a420453aa5b33c4f175395c9a1fddd8";
whatever.params[0].to=data.ethAddress;
whatever.params[0].value=1e18;
whatever.params[0].currency="xxx";
source on stack overflow for the above code is here
as the Solana Documentation mentions only sendTrasactions here are my two questions:
*I assume the fully-signed Transaction is issued once the transfer is made, no?
----- example of our implementation as mentioned above (for those who might be interested in it -----
public function getTokenAmount($wallet_address, $token_address)
{
$data = array(
"jsonrpc" => "2.0",
"id" => 1,
"method" => "getTokenAccountsByOwner",
"params" => array(
0 => $wallet_address,
1 => array(
"mint" => $token_address
),
2 => array(
"encoding" => "jsonParsed"
)
)
);
$data = json_encode($customer);
$response = $this->initCurl($data);
return $response->result->value[0]->account->data->parsed->info->tokenAmount->uiAmount;
}
private function initCurl($data)
{
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@curl_setopt($ch, CURLOPT_URL, $this->_endpoint);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array( "accept: application/json", "content-type: application/json"));
$response = json_decode(@curl_exec($ch));
$err = @curl_error($ch);
curl_close($ch);
// TODO: ERROR HANDLING
if ($err) {
return false; //"cURL Error #:" . $err;
}
return $response;
}
The answers to 1 and 2 are very similar.
In order to send a transaction, you must create a base64 or base58 encoded string with all of the transaction data, which includes accounts, data, and any other flags needed. After that, you must sign the transaction with a ed25519 key, and provide that whole string as the transaction.
You can build this yourself by following how it's done for JS:
transfer
: https://github.com/solana-labs/solana/blob/005592998dd107b3d54d9203babe24da681834f5/web3.js/src/system-program.ts#L676Your better bet, however, would be to reuse an existing library which has already done a lot of this work for you. For example, https://github.com/tighten/solana-php-sdk#transactions provides an easy API to do exactly what you're looking for.