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

I failed to get wallet v5 friendly string #354

Closed
0xBeycan opened this issue Jan 8, 2025 · 14 comments
Closed

I failed to get wallet v5 friendly string #354

0xBeycan opened this issue Jan 8, 2025 · 14 comments

Comments

@0xBeycan
Copy link

0xBeycan commented Jan 8, 2025

Hello, I can get the V4 address in the example below, but I could not get the V5 address. Can you help me with this?

import { WalletContractV4 } from "@ton/ton";
import { mnemonicToPrivateKey } from "@ton/crypto";

const mnemonics = '...'.split(' ')

const workchain = 0
const standard = {
    testOnly: true,
    bounceable: false,
}

;(async () => {
    const keyPair = await mnemonicToPrivateKey(mnemonics)
    const wallet = WalletContractV4.create({
        workchain,
        publicKey: keyPair.publicKey,
    })
    const friendlyAddress = wallet.address.toString(standard)
    console.log(friendlyAddress)
})()
@tonkeeper tonkeeper deleted a comment Jan 8, 2025
@KuznetsovNikita
Copy link
Collaborator

Hello @0xBeycan

you could see this code as a reference:

@0xBeycan
Copy link
Author

0xBeycan commented Jan 8, 2025

Thanks, by the way, I would like to ask, you can send a TON from addresses in different versions to each other. So I don't have a problem with versions in the transfer process. But when the user sends the wallet address as a parameter, how can I find out which version that address belongs to?

@0xBeycan
Copy link
Author

0xBeycan commented Jan 8, 2025

@KuznetsovNikita By the way, I already tried WalletContractV5R1 but I don't see the same address I see in my wallet in the toString method. It gives a completely different address.

@0xBeycan
Copy link
Author

0xBeycan commented Jan 8, 2025

When I examined the sample code, I saw that the walletId parameter was given and when I tried this, I got the correct output. Thanks.

Screenshot 2025-01-08 at 18 37 13
const wallet = WalletContractV5R1.create({
        workchain,
        walletId: {
            networkGlobalId: Network.TESTNET
        },
        publicKey: keyPair.publicKey,
    })

@KuznetsovNikita
Copy link
Collaborator

Thanks, by the way, I would like to ask, you can send a TON from addresses in different versions to each other. So I don't have a problem with versions in the transfer process. But when the user sends the wallet address as a parameter, how can I find out which version that address belongs to?

The easiest way you may try ‘tonapi’ method ‘getAccount’ - https://tonapi.io/api-v2

it’s work when we know a code of the contract

@0xBeycan
Copy link
Author

0xBeycan commented Jan 8, 2025

It's not possible with TonClient? I am using it now. And my mind is a little bit mixed now. Because other blockchains generally have an RPC endpoint and you can access everything with it. But TON have different API's and providers.

Also, do you know how to get transaction data by hash? ton-org/ton#77

@0xBeycan
Copy link
Author

0xBeycan commented Jan 8, 2025

Also, your main documentation is very complicated, do you know of any simpler documentation that explains how to do the basic things that we can do on other blockchains?

@KuznetsovNikita
Copy link
Collaborator

Also, your main documentation is very complicated, do you know of any simpler documentation that explains how to do the basic things that we can do on other blockchains?

It’s possible, but required to do a few steps.
Better to ask such questions here: https://t.me/tondev_eng

https://ton.org/en/dev

@0xBeycan
Copy link
Author

0xBeycan commented Jan 9, 2025

There is no such nonsense, I think he detected me as a bot and banned me. I can't join the group right now. I've looked through the Tonkeeper repos and I can't find an example of what I want. Is there an example you can give me?

@0xBeycan
Copy link
Author

0xBeycan commented Jan 9, 2025

I stole the source code for the following service and actually figured out how to do it, but man, it's slow. I really don't understand how it is not possible to get tx data with hash. All blockchains have this.

https://retracer.ton.org/

@0xBeycan
Copy link
Author

@KuznetsovNikita My friend, how can I create WalletContract from friendlyAddress?

When I parse it with address, I actually get the correct value and I can get the balance value with address again. But when I use it for WalletContract, I get a wrong friendlyAddress and balance value.

Yes, I can already create the correct WalletContract from keyPair, but what should I do in friendlyAddress?

async function createWalletFromFriendlyAddress(friendlyAddressStr: string) {
    try {
        const {address} = Address.parseFriendly(friendlyAddressStr);
        
        const workchain = 0;
        const wallet = WalletContractV5R1.create({
            workchain,
            walletId: {
                networkGlobalId: -239, // TESTNET
            },
            publicKey: address.hash
        });

        const client = new TonClient({
            endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
        });

        const onlineWallet = client.open(wallet);
        
        const walletAddress = wallet.address.toString({
            bounceable: false,
            testOnly: true
        });

        const balance = await onlineWallet.getBalance();

        return {
            address: walletAddress,
            balance: balance.toString(),
            address2: address.toString(standard),
        };
    } catch (error) {
        console.error('Wallet creation error:', error);
        throw error;
    }
}

// create wallet from friendly address
;(async () => {
    try {
        const result = await createWalletFromFriendlyAddress(
            '0QBh14OFHZqXqMyAHUio8EZ9FAf5smnkcmb0j533aHtFNcsF'
        );
        
        console.log('wallet:', result);
    } catch (error) {
        console.error('Error:', error);
    }
})()

wallet: {
address: '0QAeXZ1HpsiZT2B1FD2c_ZRet-jL1vbKfqQKD8daXOJlOoSA',
balance: '0',
address2: '0QBh14OFHZqXqMyAHUio8EZ9FAf5smnkcmb0j533aHtFNcsF'
}

@0xBeycan
Copy link
Author

@KuznetsovNikita

also I think in TON the tx fee is deducted from both addresses, not from the sending address. How do I avoid this? I tried it in Tonkeeper and my code is as below. I tried all sendModes but I always get 0.09*** even though I send 0.1.

    async sign(privateKey: PrivateKey): Promise<this> {
        const { publicKey, secretKey } = await mnemonicToPrivateKey(privateKey.split(' '))
        const contract = this.provider.createWalletV5R1(publicKey)
        this.wallet = this.provider.client1.open(contract)
        const seqno = await this.wallet.getSeqno()
        this.signedData = this.wallet.createTransfer({
            seqno,
            secretKey,
            messages: [this.rawData],
            sendMode: SendMode.PAY_GAS_SEPARATELY
        })
        return this
    }

@0xBeycan
Copy link
Author

Also how can I get tx hash? :D

    await this.provider.client1.sendExternalMessage(this.wallet, this.signedData)
        return this.signedData.hash().toString('hex')

@0xBeycan
Copy link
Author

Also, TON doesn't have approval for token spending? I mean adding a delegator.

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

2 participants