WalletKitiOS
How to transfer Gram, Jettons, and NFTs using WalletKit on the iOS platform
All methods require an existing wallet instance. Create or retrieve a wallet before accessing data.
Create transactions to send Gram, Jettons, and NFTs, or generate previews for users.
Creating a transaction
Before sending any transaction to the blockchain, initialize it for the appropriate asset: Gram, Jetton, or NFT.
Gram
// Transaction for 1 Gram
let amountFormatter = TONTokenAmountFormatter()
// Provide the user's input here
guard let amount = amountFormatter.amount(from: "1") else {
return
}
let message = TONTransferMessage(
// GRAM wallet address
toAddress: address,
amount: amount,
)
let transaction = try await wallet.transferTONTransaction(message: message)Jettons
// Transaction for 1 Jetton of some kind (e.g., USDT)
let amountFormatter = TONTokenAmountFormatter()
amountFormatter.nanoUnitDecimalsNumber = 6
// Provide the user's input here
guard let amount = amountFormatter.amount(from: "1") else {
return
}
let parameters = TONJettonTransferParams(
// GRAM wallet address
toAddress: address,
// Address of a Jetton minter contract
jettonAddress: jettonAddress,
amount: amount,
)
let transaction = try await wallet.transferJettonTransaction(parameters: parameters)NFTs
let parameters = TONNFTTransferParamsHuman(
// GRAM wallet address
toAddress: address,
// Address of an NFT item contract
nftAddress: nft.address,
)
let transaction = try await wallet.transferNFTTransaction(parameters: parameters)Transaction Preview
Once a transaction object is created, present a preview to the user before sending it.
let preview = try await wallet.preview(transaction: transaction)Sending a transaction
try await wallet.send(transaction: transaction)