PHP Algorand SDK

Hi Felipe ,

It’s Work !! :slight_smile:

Now I understand where I was wrong. I entered the wallet name instead of the ID :frowning:
Just one more question:

my genesis hash, read from the goal node status command, returns a different value than yours. If I use my value the procedure doesn’t work.

My genesis hash is : wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=

Thank you

Marco

Hi Marco,

This is a good question, YBQ4JWH4DW655UWXMBF6IVUOH5WQIGMHVQ333ZFWEC22WOJERLPQ= is wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8= base64 decoded and base32 encoded.

ex: b32::encode(base64_decode(“wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=”));

To have no confusion, I updated the SDK, now you can use Genesis Hash on base 64, according:

And Node status command / method.

You can use the new update at Github.

Hi Felipe ,
thanks for update.

To read the last round i use this :

$return=$algorand->get("v2","transactions","params");

and assign to a variable :

$return_array=json_decode($return['response']);
$lastround=$return_array->last-round ;

but I receive some errors …

Marco

I want pass last-round data for transaction array

$transaction=array(
        "txn" => array(
                "type" => "pay", //Tx Type
                "fee" => 1000, //Fee
                "fv" => $lastround, //Take the last round
                "gen" => "mainnet-v1.0", // GenesisID
                "gh" => "YBQ4JWH4DW655UWXMBF6IVUOH5WQIGMHVQ333ZFWEC22WOJERLPQ=", //Genesis Hash
                "lv" => $lastround+200, //Add 200 round 
                "note" => $content, //You note
                "snd" => "", //Sender
                "rcv" => "", //Receiver
                "amt" => 1000, //Amount
            ),
);

Marco

Because of dash “-” the correct PHP syntax is:: $return_array->{‘last-round’};

Example of use:

require_once 'sdk/algorand.php';
$algorand = new Algorand_algod('{algod-token}',"localhost",53898); //get the token key in data/algod.token and port in data/algod.net

#Get parameters for constructing a new transaction
$return=$algorand->get("v2","transactions","params");
$return_array=json_decode($return['response']);

$lastround=$return_array->{'last-round'};
print_r($return_array);

/* Response:
stdClass Object
(
    [consensus-version] => https://github.com/algorandfoundation/specs/tree/ac2255d586c4474d4ebcf3809acccb59b7ef34ff
    [fee] => 0
    [genesis-hash] => wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=
    [genesis-id] => mainnet-v1.0
    [last-round] => 13652572
    [min-fee] => 1000
)
*/

Oh , syntax problem :slight_smile:

Thanks again .

Marco

Hi Felipe,
this is Marco, I am struggling to init a wallet.

I instantiate correctly kmd and print version info, but both calls to wallet init and wallet list return the same message:

[code] => 404 [message] => {“message”:“Not Found”}

My code is the following:

$algorand_kmd = new Algorand_kmd(‘b1bdecba8a5374ea4e4b853df49f9d58c1877ee5edcbd2fba63653228dc35d74’,“localhost”,53898);

    $return=$algorand_kmd->get("versions");
    print_r($return);
    $return=$algorand_kmd->get("v1","wallets");
    print_r($return);
    //wallet init
    $params['params']=array(
        "wallet_id" => "27008546fcceca5252bf3938f21eff5e",
        "wallet_password" => "shype2022",
    );
    $return=$algorand_kmd->post("v1","wallet","init",$params);
    $return_array=json_decode($return['response']);
    print_r($return);

I found out it was just the wrong port!

Hi Marco,
Good!
Any questions let me know.
Regards

1 Like

Hi Felipe,

I need to show primary key during address creation. I use export function but receive encoded string.

How can I do this ?

Thank you
Marco

Hi Marco,

If you referring about the private key, it is already returned encoded in base 64, already in the same format needed to do the import as KMD REST APIs require.

In case you need the mnemonic words, I’m creating a version of algokey (algokey - Algorand Developer Portal) in php too, I intend to release it soon.

It’s possible to export the mnemonics using the command line ./goal account export -a {KEY}

Regards

Hi Felipe,

I need mnemonic , so for moment using goal command.

Thank you

Marco

Hi Felipe, I am trying to make an atomic transfer, with two basic transactions.
but when I try to broadcast the transactions I get this error:

[code] => 400
[message] => {"message":"TransactionPool.Remember: transactionGroup: incomplete group: 2CR4DHPI6ACSKI6T7P3VWEX5ZLEJUGXKOP2KKF2OUYN5YGLPVQLA != 2TW3AQRJYQDPBAVXGGDIQMX27FD4YCDOBANADXQAQJRSIUVBEVPQ ({{} [4LZE3BP4P66DPONNX2AENAU7JFTBWWOJ4OH7WBVX236JCF3JGQHA P6RZAYJSYKDLXWMOZZ6NAVJFNYY3FCWMGZSRQT4VMHXLGHEQ2XCQ]})"}

My code is the following:

//Transaction 1
$transactions=array();
$transactions=array(
“txn” => array(
“type” => “pay”, //Tx Type
“fee” => 1000, //Fee
“fv” => $lastRound, //First Valid
“gen” => $genesisID, // GenesisID
“gh” => $genesis, //Genesis Hash
“lv” => $lastRound+300, //Last Valid
“note” => “tx Group Test”, //You note
“snd” => $mainAccountAddress, //Sender
“rcv” => $receiver1, //Receiver
“amt” => 1000, //Amount
),
);
//Transaction 2
$transactions=array(
“txn” => array(
“type” => “pay”, //Tx Type
“fee” => 1000, //Fee
“fv” => $lastRound, //First Valid
“gen” => $genesisID, // GenesisID
“gh” => $genesis, //Genesis Hash
“lv” => ($lastRound+300), //Last Valid
“note” => “tx Group Test”, //You note
“snd” => $mainAccountAddress, //Sender
“rcv” => $receiver2, //Receiver
“amt” => 1000, //Amount
),
);

//2) Group TRansactions
$groupid=$algorand_kmd->groupid($transactions);
#Assigns Group ID
$transactions[0]['txn']['grp']=$groupid;
$transactions[1]['txn']['grp']=$groupid;

// echo "Transactions\n";
// print_r($transactions);

//3) Sign Transactions
#Sign Transaction 1
$txn="";
$params['params']=array(
//"public_key" => $algorand_kmd->pk_encode($mainAccountAddress),
"transaction" => $algorand_kmd->txn_encode($transactions[0]),
"wallet_handle_token" => $wallet_handle_token,
"wallet_password" => $mainWalletPw,
);


$return=$algorand_kmd->post("v1","transaction","sign",$params);
$r=json_decode($return['response']);
$txn.=base64_decode($r->signed_transaction);

echo "sign t1\n";
print_r($return);

#Sign Transaction 2
$params['params']=array(
//"public_key" => $algorand_kmd->pk_encode($mainAccountAddress),
"transaction" => $algorand_kmd->txn_encode($transactions[1]),
"wallet_handle_token" => $wallet_handle_token,
"wallet_password" => $mainWalletPw,
);

$return=$algorand_kmd->post("v1","transaction","sign",$params);
$r=json_decode($return['response']);
$txn.=base64_decode($r->signed_transaction);

// echo $txn;

//4) Send Transaction Group
#Broadcasts a raw atomic transaction to the network.
$params['transaction']=$txn;
$return=$algorand->post("v2","transactions",$params);
$txId=$return['response']->txId;
//echo "txId: $txId";

print_r($return);

I can’t figure out the reason of this error

Hi Marco,

Can you print the $params[‘transaction’] or $txn before the broadcast is sent to review?

Sure, This is the $txn value:

��sig�@�VN��!(Q�I ���˿-V/^H1��娱s�GZ�N[�M����JH�ʮ|@7���,ԽM��txn��amt��fee��fv�+�d�gen�testnet-v1.0�gh� Hc����N��-O��q�Y�� ��/p� :"�grp� �qi��Zњr0�w��i�͕�<-�2l �_��lv�+Đ�note�
tx Group Test�rcv� 8�|9�;��QVwW"2%����a�}�S0�3Qiܣsnd� =��!&9(�#��G ���)r�_{������type�pay��sig�@8��!Ӈ�N�:����Ű}��:q���׏���������S<&��)ʯX�1k�zs1��txn��amt��fee��fv�+�d�gen�testnet-v1.0�gh� Hc����N��-O��q�Y�� ��/p� :"�grp� �qi��Zњr0�w��i�͕�<-�2l �_��lv�+Đ�note�
tx Group Test�rcv�
c/;v�.�S�G�T��.�<�N��R�snd� =��!&9(�#��G ���)r�_{������type�paybroadcast txts

Thanks Marco, please print as base64 using echo base64_encode($txn);.

Hi Felipe:

echo (base64_encode($txn)):

gqNzaWfEQGWMYyVH+qat4m9uC259XpyXUuyzeU8DVtk1y4WbCLUn+LxlZfJOffZ+lz8y77/wKNlaHzDJv6dLgEvXaurBqAqjdHhui6NhbXTNA+ijZmVlzQPoomZ2zgEsWNujZ2VurHRlc3RuZXQtdjEuMKJnaMQgSGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiKjZ3JwxCBcmRTMhmadzOV3db5WKJZh+RRhZrjUQFpEXdYFdZ2h6KJsds4BLFoHpG5vdGXEDXR4IEdyb3VwIFRlc3SjcmN2xCACOPN8Oe87+PlRVndXIjIlr4fawAf0fcdTMP8zUWkM3KNzbmTEID303CEWJgM5KJojAKRHIIPjFekpct4RX3uup4sZAY+1pHR5cGWjcGF5gqNzaWfEQDvfnnQ30b2LJIZSRHnin7Vp8g9xqEk236Zu4qpzXXovyqAYBhZWDwZbt4kyUDh+/0eN5q3nxfLykJ57855swAajdHhui6NhbXTNA+ijZmVlzQPoomZ2zgEsWNujZ2VurHRlc3RuZXQtdjEuMKJnaMQgSGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiKjZ3JwxCBcmRTMhmadzOV3db5WKJZh+RRhZrjUQFpEXdYFdZ2h6KJsds4BLFoHpG5vdGXEDXR4IEdyb3VwIFRlc3SjcmN2xCAKYxEvAzsOdvUuEoUUU4hH0BBU7MkuFAjtPPVOmINSBqNzbmTEID303CEWJgM5KJojAKRHIIPjFekpct4RX3uup4sZAY+1pHR5cGWjcGF5

Here is the error again:

[code] => 400
[message] => {“message”:“TransactionPool.Remember: transactionGroup: incomplete group: LSMRJTEGM2O4ZZLXOW7FMKEWMH4RIYLGXDKEAWSELXLAK5M5UHUA != HWPOE2EOH4H2U56LB3EH3ARZMRGNVD4V2VVUJQEP734XPER66V3Q ({{} [SZBFO2WBWW4SCEZMMPGZA6XY2M5IR76RYORHPNHEOFXNP45DNXLQ GEECBVTA2OEJIP2HGNJLLLVPYGIT2QGIZX2CJHWJS5J76QCTUKUA]})”}

Hi Marco, I identified the problem, in some cases with note, when computing the group id, the hash did not return what was expected, I’m applying the necessary filters and encoders, I’m just doing all the necessary tests.

1 Like

Hi Felipe,

I try to remove the note field, but have same result.

Thk

Marco

Hi Felipe,

this is our version of php : PHP Version 7.2.34-28+ubuntu18.04.1+deb.sury.org+1

best
Marco