@@ -10,12 +10,13 @@ export class TRC20 extends BaseTron implements SigningWallet {
10
10
public async generateTx ( { to, amount, feeRate, extraParams } : GenerateTxInput ) : Promise < TxPayload > {
11
11
try {
12
12
const tronWeb = require ( 'tronweb' ) ;
13
- const metadata = extraParams ?. get ( 'm' ) ;
13
+ const metadata = extraParams ?. get ( this . KEY_METADATA ) ;
14
14
metadata . fee_limit = feeRate ;
15
- const decimals = extraParams ?. get ( 'd' ) ;
16
- const tokenAddress = extraParams ?. get ( 't' ) ;
17
-
15
+ const decimals = extraParams ?. get ( this . KEY_DECIMALS ) ;
16
+ const tokenAddress = extraParams ?. get ( this . KEY_TOKEN_ADDRESS ) ;
18
17
const fixedAmount = amount * 10 ** decimals ;
18
+
19
+ //serialized data - functionSelector(transfer) + toAddress + amount
19
20
const data = `a9059cbb${ tronWeb . address . toHex ( to ) . replace ( '/^(41)/' , '0x' ) . padStart ( 64 , '0' ) } ${ fixedAmount
20
21
. toString ( 16 )
21
22
. padStart ( 64 , '0' ) } `;
@@ -50,7 +51,7 @@ export class TRC20 extends BaseTron implements SigningWallet {
50
51
tx . raw_data_hex = tronWeb . utils . transaction . txPbToRawDataHex ( pb ) . toLowerCase ( ) ;
51
52
const signedTx = tronWeb . utils . crypto . signTransaction ( Buffer . from ( this . privateKey ! . replace ( '0x' , '' ) , 'hex' ) , tx ) ;
52
53
53
- //encode and compress for qr code
54
+ //encode and compress to fit qr code limits
54
55
const gzip = promisify ( zlib . gzip ) ;
55
56
const compressedTx = ( await gzip ( JSON . stringify ( signedTx ) ) ) . toString ( 'base64' ) ;
56
57
0 commit comments