PHP code example of catchain / ton-address

1. Go to this page and download the library: Download catchain/ton-address library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

catchain / ton-address example snippets


use Catchain\Ton\Address\Address;

Address::isValid('EQB/tWkYGPdyPxqz8TXjVaSTKfr1gOOPqOez4d07vHFqUMuk');
// >>> true

Address::isValid('this-is-definitely-not-an-address');
// >>> false

$address = Address::parse('-1:811ced271f8f449cb51eb5920090b92cb200b20f07170676e9db6fbe9da516cf');

// or in any other format:

$address = Address::parse('Uf+BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22++naUWz5id');

$address->toString(
  userFriendly: true,
  urlSafe: true,
  bounceable: true,
  testOnly: false,
);

// >>> Ef-BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22--naUWz8VY

$address->toString(userFriendly: false);

// >>> -1:811ced271f8f449cb51eb5920090b92cb200b20f07170676e9db6fbe9da516cf

Address::parse('Uf+BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22++naUWz5id')->toString();
// >>> Uf+BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22++naUWz5id

Address::parse('kf-BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22--naUWz37S')->toString();
// >>> kf-BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22--naUWz37S