ton-connect / sdk

SDK for TON Connect 2.0 — a comprehensive communication protocol between wallets and apps in TON ecosystem
Apache License 2.0
267 stars 69 forks source link

How can I use Send transaction on my web end to complete the transfer? #106

Closed W123-T closed 10 months ago

W123-T commented 10 months ago
How can I use Send transaction on my web end to complete the transfer? I used demo but there was no response。 /xxxxxx/ if (!connector.connected) { alert('Please connect wallet to send the transaction!'); } const transaction = { validUntil: Math.floor(Date.now() / 1000) + 60, // 60 sec messages: [ { address: "EQBBJBB3HagsujBqVfqeDUPJ0kXjgTPLWPFFffuNXNiJL0aA", amount: "20000000", // stateInit: "base64bocblahblahblah==" // just for instance. Replace with your transaction initState or remove }, { address: "EQDmnxDMhId6v1Ofg_h5KR5coWlFG6e86Ro3pc7Tq4CA0-Jn", amount: "60000000", // payload: "base64bocblahblahblah==" // just for instance. Replace with your transaction payload or remove } ] } try { const result = await connector.sendTransaction(transaction); // you can use signed boc to find the transaction const someTxData = await myAppExplorerService.getTransaction(result.boc); alert('Transaction was sent successfully', someTxData); } catch (e) { if (e instanceof UserRejectedError) { alert('You rejected the transaction. Please confirm it to send to the blockchain'); } else { alert('Unknown error happened', e); } } /xxxxxx/
thekiba commented 10 months ago

The code snippet you provided appears to be correct and should send the transaction and then retrieve the transaction status using the myAppExplorerService.getTransaction() method which you have created by yourself.

However, it is recommended to use tonConnectUI.sendTransaction() from @tonconnect/ui-react or @tonconnect/ui instead of connector.sendTransaction(). This is because UI packages have built-in handlers for displaying modal windows and notifications. The usage is almost the same as the example you provided, but instead of calling connector.sendTransaction(), you would call tonConnectUI.sendTransaction().

Additionally, please make sure that the wallet is indeed connected through TON Connect at the time of sending the transaction. Also, verify that the validUntil parameter is not expired; otherwise, it may cause an error.

W123-T commented 10 months ago

Thank you, but where does this myAppExplorerService come from,How should I implement it,I used @ tonconnect/ui repeat, and when using sendTransaction, it was in a loading state. The window prompted me to 'Confirm the transaction in Tonkeeper' It will only take a moment , This is my demo code: /xxxx/

const Content: React.FC<IContentProps> = ({ }) => {
    const [tonConnectUI] = useTonConnectUI();
    const myTransaction = {
        validUntil: Math.floor(Date.now() / 1000) + 10000, 
        messages: [
            {
                address: "EQBBJBB3HagsujBqVfqeDUPJ0kXjgTPLWPFFffuNXNiJL0aA",
                amount: "20000000",
                // stateInit: "base64bocblahblahblah==" // just for instance. Replace with your transaction initState or remove
            },

        ]
    }
    return (
        <div>
            <button onClick={() => {
                tonConnectUI.sendTransaction(myTransaction);
                myAppExplorerService.getTransaction();
                }}>
                Send transaction
            </button>

        </div>
    );
}

/xxxx/

mypeaceduck commented 4 months ago

Hello friends, myAppExplorerService.getTransaction() how to wait and show the success message to the user?

tarikhagustia commented 4 months ago

Hi, please open this issue again i also still confused how to get transaction detail by boc @thekiba

fooshyangsong commented 4 months ago

Hello, the readme example is using this myAppExplorerService.getTransaction(). Is there a sample code ?

The current method i know is getting the convert the bloc and get msg hash then use find transaction by msg hash method

const bocCell = tonweb.boc.Cell.oneFromBoc(tonweb.utils.base64ToBytes(blocString)); const YOUR_MSG_HASH= tonweb.utils.bytesToBase64(await bocCell.hash()); console.log("Msg Hash:", hash);

https://testnet.tonscan.org/tx/by-msg-hash/YOUR_MSG_HASH

huangxok commented 3 months ago

https://github.com/ton-connect/sdk/issues/106#issuecomment-2116506961 yes , is there a resolution for get hash by boc?