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

How to write a contract in which sender can send his Jetton-Token to other account? #43

Open
immujahidkhan opened this issue Oct 10, 2024 · 1 comment

Comments

@immujahidkhan
Copy link

How to write a contract in which sender can send his Jetton-Token to other account?

MoonAddress is : kQCuxTAQFigrc0jjyU1RvR3otVougTarJRkbAHZ7dCK-YjPs

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

}

Look trx:
tonscan: https://testnet.tonscan.org/address/EQDCCLrXNfrszyTQlBjJCAiROUb18XdP7jcwmz63fbNpzi6P
tonviewer:https://testnet.tonviewer.com/kQDCCLrXNfrszyTQlBjJCAiROUb18XdP7jcwmz63fbNpzpUF

I tried but got failed why please help or guide me how to acheive this

@immujahidkhan
Copy link
Author

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