-
Notifications
You must be signed in to change notification settings - Fork 163
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
send jettons #288
Comments
Hello, have you solved this problem? |
Yes i have here the full code:
dont forget to set correct opcode of the contract the code perfectly works for me but if didnt work for you check this part of code: the value of "to" is my jetton wallet and i think it must be recipment jetton address. or im wrong because the code works fine |
Hello my friend. I have a question for you and I expect you to help me.
Because successful people never stop helping amateurs.
How can I transfer my balance of coins and NFTs to my personal
cryptocurrency wallet?
…On سهشنبه ۲۲ اکتبر ۲۰۲۴، ۰:۴۱ F4RD1N ***@***.***> wrote:
Hello, have you solved this problem?
Yes i have
here the full code:
const { beginCell, Address, TonClient, WalletContractV4, internal,
external, storeMessage, toNano } = require( ***@***.***/ton');
const nacl = require('tweetnacl');
const { mnemonicToWalletKey } = require("ton-crypto");
const apiKey = 'YOUR-API-KEY-HERE';
const client = new TonClient({ endpoint: '
https://toncenter.com/api/v2/jsonRPC', apiKey });
async function getUserJettonWalletAddress(userAddress, contractAddress) {
const userAddressCell =
beginCell().storeAddress(Address.parse(userAddress)).endCell();
const response = await client.runMethod(Address.parse(contractAddress),
'get_wallet_address', [
{ type: 'slice', cell: userAddressCell },
]);
return response.stack.readAddress();
}
async function getWalletDetails(mnemonic) {
// Step 1: Get wallet keypair (secretKey and publicKey) from mnemonic
const formattetMnemonic = mnemonic.split(" ")
const walletKey = await mnemonicToWalletKey(formattetMnemonic);
const publicKey = walletKey.publicKey;
const secretKey = walletKey.secretKey;
// Step 2: Create a v4 wallet contract and derive the address
const wallet = WalletContractV4.create({
publicKey: publicKey, // Use the public key from the wallet keypair
workchain: 0 // Usually, the workchain is 0 for normal accounts
});
const walletAddress = wallet.address;
return {
secretKey: secretKey.toString('hex'), // Convert to hex format for readability
publicKey: publicKey.toString('hex'), // Convert to hex format for readability
walletAddress: walletAddress.toString() // Get the wallet address as a string
};
}
const sendToken = async ({mnemonic, recipment, amount, contractAddress})
=> {
const wal = await getWalletDetails(mnemonic)
const keyPair = nacl.sign.keyPair.fromSecretKey(Buffer.from(wal.secretKey,
'hex'));
const secretKey = Buffer.from(keyPair.secretKey);
const publicKey = Buffer.from(keyPair.publicKey);
const workchain = 0; // Usually you need a workchain 0
const wallet = WalletContractV4.create({ workchain, publicKey });
const address = wallet.address.toString({ urlSafe: true, bounceable:
false, testOnly: false });
const contract = client.open(wallet);
const balance = await contract.getBalance();
// console.log({ address, balance });
const seqno = await contract.getSeqno();
const { init } = contract;
const contractDeployed = await
client.isContractDeployed(Address.parse(address));
let neededInit = null;
if (init && !contractDeployed) {
neededInit = init;
}
const jettonWalletAddress = await getUserJettonWalletAddress(address,
contractAddress);
// Comment payload
// const forwardPayload = beginCell()
// .storeUint(0, 32) // 0 opcode means we have a comment
// .storeStringTail('Hello, TON!')
// .endCell();
const messageBody = beginCell()
.storeUint(0xf8a7ea5, 32) // opcode for jetton transfer
.storeUint(0, 64) // query id
.storeCoins(amount * 10**9) // jetton amount, amount * 10^9
.storeAddress(Address.parse(recipment)) // jetton recipient
.storeAddress(Address.parse(wal.walletAddress)) // response destination
.storeBit(0) // no custom payload
.storeCoins(0) // forward amount - if > 0, will send notification message
.storeBit(0) // we store forwardPayload as a reference, set 1 and
uncomment next line for have a comment
// .storeRef(forwardPayload)
.endCell();
const internalMessage = internal({
to: jettonWalletAddress,
value: toNano('0.1'),
bounce: true,
body: messageBody,
});
const body = wallet.createTransfer({
seqno,
secretKey,
messages: [internalMessage],
});
const externalMessage = external({
to: address,
init: neededInit,
body,
});
const externalMessageCell =
beginCell().store(storeMessage(externalMessage)).endCell();
const signedTransaction = externalMessageCell.toBoc();
const hash = externalMessageCell.hash().toString('hex');
await client.sendFile(signedTransaction);
return {
hash,
recipment,
sender: wal.walletAddress,
amount
}
}
(async () => {
const mnemonic = "YOUR MNEMONIC HERE"
const recipment = "RECIPIENT ADDRESS HERE"
const contractAddress = "THE CONTRACT ADDRESS HERE"
const result = await sendToken({mnemonic, recipment, amount:50,
contractAddress})
console.log(result);
})()
dont forget to set correct opcode of the contract
this is for DOGS:
.storeUint(0xf8a7ea5, 32)
the code perfectly works for me but didnt work for you check this code
here:
to: jettonWalletAddress,
the value of "to" is my jetton wallet and i think it must be recipment
jetton address. or im wrong because the code works fine
—
Reply to this email directly, view it on GitHub
<#288 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BKFG5JLTGV43TPNQYLBJJF3Z4VUXRAVCNFSM6AAAAABQHP33JWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRXG4ZDMMRRGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
And what do I need to do to send my doggs to your GitHub account?! I don't
understand the codes you sent me at all.
I want you to guide me more clearly
…On سهشنبه ۲۲ اکتبر ۲۰۲۴، ۳:۲۸ خلیل موسوی ***@***.***> wrote:
Hello my friend. I have a question for you and I expect you to help me.
Because successful people never stop helping amateurs.
How can I transfer my balance of coins and NFTs to my personal
cryptocurrency wallet?
On سهشنبه ۲۲ اکتبر ۲۰۲۴، ۰:۴۱ F4RD1N ***@***.***> wrote:
> Hello, have you solved this problem?
>
> Yes i have
>
> here the full code:
> const { beginCell, Address, TonClient, WalletContractV4, internal,
> external, storeMessage, toNano } = require( ***@***.***/ton');
> const nacl = require('tweetnacl');
> const { mnemonicToWalletKey } = require("ton-crypto");
> const apiKey = 'YOUR-API-KEY-HERE';
> const client = new TonClient({ endpoint: '
> https://toncenter.com/api/v2/jsonRPC', apiKey });
>
> async function getUserJettonWalletAddress(userAddress, contractAddress) {
> const userAddressCell =
> beginCell().storeAddress(Address.parse(userAddress)).endCell();
>
> const response = await client.runMethod(Address.parse(contractAddress),
> 'get_wallet_address', [
> { type: 'slice', cell: userAddressCell },
> ]);
>
> return response.stack.readAddress();
> }
>
> async function getWalletDetails(mnemonic) {
> // Step 1: Get wallet keypair (secretKey and publicKey) from mnemonic
> const formattetMnemonic = mnemonic.split(" ")
> const walletKey = await mnemonicToWalletKey(formattetMnemonic);
>
> const publicKey = walletKey.publicKey;
> const secretKey = walletKey.secretKey;
>
> // Step 2: Create a v4 wallet contract and derive the address
> const wallet = WalletContractV4.create({
> publicKey: publicKey, // Use the public key from the wallet keypair
> workchain: 0 // Usually, the workchain is 0 for normal accounts
> });
>
> const walletAddress = wallet.address;
>
> return {
> secretKey: secretKey.toString('hex'), // Convert to hex format for readability
> publicKey: publicKey.toString('hex'), // Convert to hex format for readability
> walletAddress: walletAddress.toString() // Get the wallet address as a string
> };
>
> }
>
> const sendToken = async ({mnemonic, recipment, amount, contractAddress})
> => {
> const wal = await getWalletDetails(mnemonic)
>
> const keyPair =
> nacl.sign.keyPair.fromSecretKey(Buffer.from(wal.secretKey, 'hex'));
> const secretKey = Buffer.from(keyPair.secretKey);
> const publicKey = Buffer.from(keyPair.publicKey);
>
> const workchain = 0; // Usually you need a workchain 0
> const wallet = WalletContractV4.create({ workchain, publicKey });
> const address = wallet.address.toString({ urlSafe: true, bounceable:
> false, testOnly: false });
> const contract = client.open(wallet);
>
> const balance = await contract.getBalance();
> // console.log({ address, balance });
>
> const seqno = await contract.getSeqno();
>
> const { init } = contract;
> const contractDeployed = await
> client.isContractDeployed(Address.parse(address));
> let neededInit = null;
>
> if (init && !contractDeployed) {
> neededInit = init;
> }
>
> const jettonWalletAddress = await getUserJettonWalletAddress(address,
> contractAddress);
>
> // Comment payload
> // const forwardPayload = beginCell()
> // .storeUint(0, 32) // 0 opcode means we have a comment
> // .storeStringTail('Hello, TON!')
> // .endCell();
>
> const messageBody = beginCell()
> .storeUint(0xf8a7ea5, 32) // opcode for jetton transfer
> .storeUint(0, 64) // query id
> .storeCoins(amount * 10**9) // jetton amount, amount * 10^9
> .storeAddress(Address.parse(recipment)) // jetton recipient
> .storeAddress(Address.parse(wal.walletAddress)) // response destination
> .storeBit(0) // no custom payload
> .storeCoins(0) // forward amount - if > 0, will send notification message
> .storeBit(0) // we store forwardPayload as a reference, set 1 and
> uncomment next line for have a comment
> // .storeRef(forwardPayload)
> .endCell();
>
> const internalMessage = internal({
> to: jettonWalletAddress,
> value: toNano('0.1'),
> bounce: true,
> body: messageBody,
> });
>
> const body = wallet.createTransfer({
> seqno,
> secretKey,
> messages: [internalMessage],
> });
>
> const externalMessage = external({
> to: address,
> init: neededInit,
> body,
> });
>
> const externalMessageCell =
> beginCell().store(storeMessage(externalMessage)).endCell();
>
> const signedTransaction = externalMessageCell.toBoc();
> const hash = externalMessageCell.hash().toString('hex');
>
> await client.sendFile(signedTransaction);
>
> return {
> hash,
> recipment,
> sender: wal.walletAddress,
> amount
> }
> }
>
> (async () => {
> const mnemonic = "YOUR MNEMONIC HERE"
> const recipment = "RECIPIENT ADDRESS HERE"
> const contractAddress = "THE CONTRACT ADDRESS HERE"
>
> const result = await sendToken({mnemonic, recipment, amount:50,
> contractAddress})
> console.log(result);
> })()
>
> dont forget to set correct opcode of the contract
> this is for DOGS:
> .storeUint(0xf8a7ea5, 32)
>
> the code perfectly works for me but didnt work for you check this code
> here:
> to: jettonWalletAddress,
>
> the value of "to" is my jetton wallet and i think it must be recipment
> jetton address. or im wrong because the code works fine
>
> —
> Reply to this email directly, view it on GitHub
> <#288 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BKFG5JLTGV43TPNQYLBJJF3Z4VUXRAVCNFSM6AAAAABQHP33JWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRXG4ZDMMRRGA>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
|
you dont need to send me anything |
Thanks for the tip!
…On Tue, Oct 22, 2024, 04:31 F4RD1N ***@***.***> wrote:
you dont need to send me anything
all you need is a simple knowledge of javascript and thats it. the code i
sent to you is easy to read and use. but if you dont understrand javascript
unfortunately at all, it cannot help you. made the code easy to use for you
you just need an API key, your 24 phrase key of the wallet you want to
transfer tokens, recipment wallet address and token contract address(
Master)
if you dont know all of these stuff you should learn some javascript and
need a little bit knowledge of working with ton wallet addresses and jetton
transfer in blockchain
—
Reply to this email directly, view it on GitHub
<#288 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BKFG5JLFLYEZBYJY72ZP75TZ4WPWRAVCNFSM6AAAAABQHP33JWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRYGAYDKMBXGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
hi
i want to send jettons programmatically using tonweb.
the transaction will be created but call contract will be failed.
this is my function to sen jettons:
async sendToken(toAddress, tokenContractAddress, tokenAmount, memo) {
try {
const jettonWallet = new TonWeb.token.jetton.JettonWallet(this.tonweb, {
address: tokenContractAddress,
});
}
the payload sent is something like this:
Amount: "100000000000"
CustomPayload: null
Destination: 0:8b023234sdflkjfj409w3929j09jewfdsfd69c1a326463d2f1
ForwardPayload:
IsRight: false
Value:
OpCode: 0
SumType: TextComment
Value:
Text: hello
ForwardTonAmount: "70000000"
QueryId: 0
ResponseDestination: 0:8b0230bf3f6aaf623eb8c15e25d2e6f48ab76d9af9a811d1fwf94w324982
The text was updated successfully, but these errors were encountered: