olifanton / ton

PHP SDK library for The Open Network blockchain
MIT License
39 stars 4 forks source link

Can you provide an example of a USDT transfer? #11

Closed wartw closed 3 months ago

wartw commented 3 months ago

Can you provide an example of a USDT transfer?

romanzaycev commented 3 months ago
$recipient = new Address(""); // USDT recepient wallet address 
$usdtTransferAmount = Units::toNano(0.1);

// ====

$wallet = new WalletV3R2( // Your wallet
    new WalletV3Options(
        publicKey: $kp->publicKey,
    ),
);
$walletAddress = $wallet->getAddress();

$usdtRoot = JettonMinter::fromAddress(
    $transport,
    new Address("EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"), // USDT minter address https://tonviewer.com/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs
);
$usdtWalletAddress = $usdtRoot->getJettonWalletAddress($transport, $walletAddress);
$usdtWallet = new JettonWallet(new JettonWalletOptions(
    address: $usdtWalletAddress,
));

$extMsg = $wallet->createTransferMessage([
    new Transfer(
        dest: $usdtWalletAddress,
        amount: Units::toNano("0.04"),
        payload: $usdtWallet->createTransferBody(new TransferJettonOptions(
            jettonAmount: $usdtTransferAmount,
            toAddress: $recipient,
            responseAddress: $walletAddress,
        )),
        sendMode: SendMode::IGNORE_ERRORS->combine(SendMode::PAY_GAS_SEPARATELY)
    ),
]);
$transport->sendMessage($extMsg, $kp->secretKey);
wartw commented 3 months ago

THANK