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:
- how to implement the above example using Solana (see below our curl implementation of the Solana JSONRPC to get a user's current token amount in php i.e. "getTokenAmount")
- where do I get the fully-signed Transaction as an encoded string which is a parameter for the "sendTransaction"*
*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;
}