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 can a sender's transfer his own Jetton token to recipientAddress? #39

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

Comments

@immujahidkhan
Copy link

import "@stdlib/deploy";
import "./google";
message MyTransfer {
amount: Int as coins;
}

contract InitiateJettonTransfer with Deployable {
masterAddress: Address;
recipientAddress: Address;
// Initialize with the master contract address, the recipient, and the amount of Jettons
init(master: Address, recipient: Address){
self.masterAddress = master;
self.recipientAddress = recipient;
}

fun getJettonWalletAddress(user: Address): Address {
    let walletInit: StateInit = initOf JettonDefaultWallet(user, self.masterAddress);
    return contractAddress(walletInit);
}

// Method to initiate the transfer of Jettons

receive(msg: MyTransfer){
    let senderWallet: Address = self.getJettonWalletAddress(sender());
    // Construct the TokenTransfer message using the provided message type
    let transferMessage: TokenTransfer = TokenTransfer{
        queryId: 0, // Set query ID to 0
        amount: msg.amount, // The amount of Jettons to transfer
        destination: self.recipientAddress, // Destination address for Jettons
        response_destination: myAddress(), // Response destination (optional)
        custom_payload: null, // No custom payload
        forward_ton_amount: 0, // Forward TON amount (optional, set to 0)
        forward_payload: emptySlice() // Empty forward payload (optional)
    };
    // Send the transfer message to the sender's wallet
    send(SendParameters{
            to: senderWallet,
            value: ton("0.05"), // Gas fee
            bounce: true,
            body: transferMessage.toCell() // Convert the message to a Cell and send it
        }
    );
}

}

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