Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetton Transfer Token (External) #9

Open
immujahidkhan opened this issue Oct 10, 2024 · 0 comments
Open

Jetton Transfer Token (External) #9

immujahidkhan opened this issue Oct 10, 2024 · 0 comments

Comments

@immujahidkhan
Copy link

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);
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant