skip to Main Content

The address generated by trc20 in the method and in the hot wallet does not match when using the same mnemonic phrase

Hello! I’m trying to write a method that will generate a TRC20 wallet from a mnemonic phrase and also access an existing wallet on the same network. I found a package a package that should help me – wallet. 


import 'package:wallet/wallet.dart'; 
import 'package:bip39/bip39.dart' as bip39;

void getTrc20Address() async {  
    final tron = await Tron();
    
    String randomMnemonic = bip39.generateMnemonic();  
     final seed = bip39.mnemonicToSeed(randomMnemonic);
    
    final privKey = tron.createPrivateKey(seed);
    
    final pubKey = tron.createPublicKey(privKey);
    
    final address = tron.createAddress(pubKey);  
    print(address);  
}

TRc20 address is created correctly, it turns out to send a transaction to it, but when I try to authorize through the phrase created in the mnemonic method in a hot wallet (for example, trust wallet) – the address issued by the wallet differs from what I get in the method.

Example:

the phrase used to generate the wallet in the method: ‘boost limit you peasant april setup print arrest love festival much consider’, and in the method with it the address TZ5kGfid2b7FdP3VaqcFf7PKDC64s7htzB is created, while in the trust wallet with the same phrase I connect to the wallet TY2wEqpxfw6ZK9hXWVat5hKgyrPqg2dfy3.  

Where i made a mistake?

2

Answers


  1. well this might be the same address without checksum.
    tron uses base58 checksum which has the algorithm like below:

    1.Concatenate the raw address bytes with a 4-byte checksum. The checksum is computed by taking the Keccak-256 hash of the raw address bytes and taking the first 4 bytes of the hash.
    
    2.Convert the concatenated string to a big integer.
    
    3.Divide the big integer repeatedly by 58, computing the remainder at each step. The remainders form the digits of the Base58Check-encoded address.
    
    4.Append the appropriate Base58Check-encoded characters to the result. The characters used in Base58Check are a modified set of the characters used in Base58 for Bitcoin addresses.
    
    5.If any leading zero bytes were present in the raw address, represent them in the Base58Check-encoded address with the character T.
    
    6.Return the final Base58Check-encoded address.
    
    Here is an example of how to generate a TRON Base58Check address from the raw address bytes:
    
    1.Raw address bytes: 0028c03f279a1046bead4c4e150fb8b80ee57f56a5
    
    2.Compute the checksum: 0x155b0d1c
    
    3.Concatenate the raw address bytes with the checksum: 0028c03f279a1046bead4c4e150fb8b80ee57f56a5155b0d1c
    
    4.Convert to a big integer: 5631415186761214005450108940862773119903188035575
    
    5.Divide repeatedly by 58, taking remainders: g9CvdZL1SpZXXwvfiD
    
    6.Replace leading zero bytes with T: Tg9CvdZL1SpZXXwvfiD
    
    7.Return the final Base58Check-encoded address: Tg9CvdZL1SpZXXwvfiD
    

    this algorithm is generated by ai chat bot so it might not be the true one but it’s almost like this.

    Login or Signup to reply.
  2.  wallet: ^0.0.11
    
    
    Uint8List seed = bip39.mnemonicToSeed(seedPhrase);
      final master = wallet.ExtendedPrivateKey.master(seed, wallet.xprv);
      final root = master.forPath("m/44'/195'/0'/0/0");
    
      final privateKey = wallet.PrivateKey((root as wallet.ExtendedPrivateKey).key);
      final publicKey = wallet.tron.createPublicKey(privateKey);
      final address = wallet.tron.createAddress(publicKey);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search