PHP Algorand SDK

Nice, tomorrow I’ll upload an update that will solve this problem, I’ll let you know here.

Hi Marco,

I updated the github repository, just replace the /sdk/algorand.php file.

Regards

Felipe

Hi Felipe,

we receive this error now on algorand.php :

PHP Parse error: syntax error, unexpected ‘=>’ (T_DOUBLE_ARROW), expecting ‘,’ or ‘)’ in /sdk/algorand.php on line 504.

Line:

$out[‘txn’]=array_filter($out[‘txn’], fn($val) =>! is_null($val) AND $val !== “” AND $val !==0 AND $val !== false);

Marco

Hi Marco, sorry, I missed adding PHP 7.2 support too, it was only tested on PHP 7.4 later. I updated the repository again, now it works with PHP 7.2 too.

Hi Felipe,

thank for fast reply. Now AT work but have a issue on writing note on blockchain.

Our routine write note in json but now write as message Pack.

I take a look to your sdk code ,

if(!empty($out[‘txn’][‘note’])) { $out[‘txn’][‘note’]=$msgpack->pBin(utf8_encode(strval($out[‘txn’][‘note’]))); }

What is the behavior of ?

Can I change here to resolve the issue ?

Marco

Hi Marco,

Thanks for this report too, notes don’t need msgpack encode in atomic transfers. I updated the repository fixing this too, this and another line have been updated.

Regards

Nice :slight_smile:
Now work as expected .

Thank you .

Marco

Hi Felipe,
just for curiosity, but what is the purpose of this :

$out=str_replace(“6e6f7465d9”,“6e6f7465c4”,bin2hex($out));

Regards

This is a filter for the msgpack php to be compatible with the msgpack algorand to generate the same hash of the group id.

Hi Felipe, how are you ?

We always use your SDK for PHP:-)

I have a little probs:

I use code for create ASA , all working fine, but we need to know the ID of this as a response of transaction.

There is a method to acquire during creation ?

Thanks

Marco

Hi Felipe, I just installed the SDK, it’s all fine, but sending the notes in plain text as intended that’s what I get

immagine

there’s always an encoding error

this is the code I use, if that helps

	$algorand = new Algorand(....);

	$suggestedparam=$algorand->get("v2","transactions","params");
	$sp=json_decode($suggestedparam['response']);
	
	$note = "just a text note";

	$transaction=array(
			"txn" => array(
					"aamt" => $amount,
					"type" => "axfer", //Tx Type
					"arcv" => $receiver, //AssetReceiver
					"snd" => $sender, //Sender
					"fee" => $sp->{'min-fee'}, //Fee
					"fv" => $sp->{'last-round'}, //First Valid
					"lv" => $sp->{'last-round'}+1000, //Last Valid
					"gh" => $sp->{'genesis-hash'}, //Genesis Hash
					"xaid" => $assetid, //XferAsset ID
					"note" => $note, //Your note
				),
	);


	$transaction_raw=$algorand_transactions->encode($transaction);
	$signature=$algokey->sign($transaction_raw,$privateKey);
	$transaction_raw_signed=$algorand_transactions->encode($transaction,true,$signature);

	$params['transaction']=$transaction_raw_signed;
	$return=$algorand->post("v2","transactions",$params);

Hi Marco! You need to use the returned TX ID and make a query to view the ASA ID or list the tokens created in your address. The Algorand blockchain does not return directly.

Hi @mmorselli !

Thank you for the report; I will check and provide a solution or correction soon.

Hi Felipe,
Yes I use this method , but I see with python or js it’s possible.

const suggestedParams = await algodClient.getTransactionParams().do();
const txn = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({
  from: creator.addr,
  suggestedParams,
  defaultFrozen: false,
  unitName: 'rug',
  assetName: 'Really Useful Gift',
  manager: creator.addr,
  reserve: creator.addr,
  freeze: creator.addr,
  clawback: creator.addr,
  assetURL: 'http://path/to/my/asset/details',
  total: 1000,
  decimals: 0,
});

const signedTxn = txn.signTxn(creator.privateKey);
await algodClient.sendRawTransaction(signedTxn).do();
const result = await algosdk.waitForConfirmation(
  algodClient,
  txn.txID().toString(),
  3
);

const assetIndex = result['asset-index'];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
console.log(`Asset ID created: ${assetIndex}`);


Can I do this with PHP ?

Thanks

thanks, also there seems to be problems with notes longer than 127 characters. Shouldn’t the limit be 1000 bytes for the whole transaction?

2023-10-14 04:03:58 - note length 128
2023-10-14 04:03:58 - NOTE: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
2023-10-14 04:03:58 - transaction length 325
2023-10-14 04:03:58 - At least one signature didn't pass verification

if I remove a single A from the string the transaction starts