Skip to content

Jetton Transfer Token (External) #9

@immujahidkhan

Description

@immujahidkhan

How a sender can transfer/send his own Jetton Token to other account using external contract?
i tried but failed why? https://testnet.tonviewer.com/transaction/cf11c288fa697dc047e42c1bf33bec0b7395f4935706204d4710b4eb9fdc325d

`
import "@stdlib/deploy";
import "./jet_ton.tact";

contract Jutt with Deployable {
moonAddress: Address; // Store Moon Jetton contract address

// Initialize with Moon Jetton contract address
init(moonJetton: Address){
    self.moonAddress = moonJetton;
}

// Function to transfer Moon tokens using the Jutt contract
receive("transferMoonTokens"){
    let senderWallet: Address = self.getSenderJettonWallet(); // Get sender's Jetton wallet
    let recipientWallet: Address = self.getRecipientJettonWallet(); // Get recipient's Jetton wallet
    let amount: Int = self.getAmount(); // Get the amount to transfer

    // Create the transfer message for the sender's Jetton wallet
    send(SendParameters{
            to: senderWallet,
            value: ton("0.1"), // Provide a small amount of TON for gas fees
            body: TokenTransfer{
                queryId: 0,
                amount: amount,
                destination: recipientWallet,
                response_destination: myAddress(), // Response destination for excess or notifications
                custom_payload: null,
                forward_ton_amount: ton("0.05"), // Forward TON for recipient's gas
                forward_payload: emptySlice() // Additional message/comment if needed
            }.toCell()
        }
    );
    dump("Moon tokens transferred successfully");
}

// Example function to get the sender's Jetton wallet address
fun getSenderJettonWallet(): Address {
    return self.getJettonWalletAddress(sender()); // Get Jetton wallet for sender
}

// Example function to get the recipient's Jetton wallet address

fun getRecipientJettonWallet(): Address {
    let recipient: Address = self.getRecipient(); // Get recipient address
    return self.getJettonWalletAddress(recipient); // Get Jetton wallet for recipient
}

// Get recipient address (replace with actual logic)

fun getRecipient(): Address {
    return address("0QCBeq_ECrBXkh8mW-0DhNMUmAvkyyDYlBxq1_A4pfiNg3tC"); // recipient address
}

// Example function to get the amount, replace with actual logic

fun getAmount(): Int {
    return ton("1000"); // Amount of Moon tokens to transfer
}

// Utility function to get Jetton wallet address based on the owner address

fun getJettonWalletAddress(owner: Address): Address {
    let init: StateInit = initOf JettonDefaultWallet(self.moonAddress, owner);
    return contractAddress(init);
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions