Last active
November 15, 2023 04:43
-
-
Save romanzaycev/59dff394637e6d81fabc995b0057b7cc to your computer and use it in GitHub Desktop.
[PHP] TON wallet address generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ton_wallet_address.php | |
// PHP 8.1 is required | |
use Olifanton\Mnemonic\TonMnemonic; | |
use \Olifanton\Ton\Contracts\Wallets\V3 as V3; | |
use \Olifanton\Ton\Contracts\Wallets\V4 as V4; | |
// 1. composer require olifanton/ton | |
require_once __DIR__ . "/vendor/autoload.php"; | |
// 2. Generate Seed phrase | |
$words = TonMnemonic::generate(); | |
// 3. Save seed phrase to file | |
file_put_contents(__DIR__ . "/words_" . date("Y_m_d_H_i_s") . ".txt", implode(" ", $words)); | |
// 4. Create keypair from seed phrase | |
$kp = TonMnemonic::mnemonicToKeyPair($words); | |
// 5. Create Wallets instances | |
/** @var \Olifanton\Ton\Contracts\Wallets\Wallet[] $wallets */ | |
$wallets = [ | |
new V3\WalletV3R1(new V3\WalletV3Options($kp->publicKey)), | |
new V3\WalletV3R2(new V3\WalletV3Options($kp->publicKey)), | |
new V4\WalletV4R1(new V4\WalletV4Options($kp->publicKey)), | |
new V4\WalletV4R2(new V4\WalletV4Options($kp->publicKey)), | |
]; | |
// 6. Iterate Wallet's instances and print their addresses | |
foreach ($wallets as $wallet) { | |
echo $wallet->getName(), ": ", $wallet->getAddress()->toString(isUserFriendly: true, isUrlSafe: true, isBounceable: false), PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment