tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
440 stars 277 forks source link

Stake 2.0 (transactionBuilder.freezeBalanceV2) not working #376

Closed dappd closed 1 year ago

dappd commented 1 year ago

hey guys. I am using TronWeb lib to create wallets, send TRX, USDT and it's all working as expected. Now I am trying to implement staking using new version 2.0. I use newly implemented method freezeBalanceV2, receive successful response but the actual transaction doesn't exist on chain and resources are not stacked. Here is my setup:

import * as TronWeb from "tronweb"
const tronWeb = new TronWeb({
            fullHost: "https://api.shasta.trongrid.io",
            privateKey: "3e62axxx...xxx4f067",
            headers: {
                'TRON-PRO-API-KEY': "my-pro-key"
            }
        })
const result = await tronWeb.transactionBuilder.freezeBalanceV2(10000000, "ENERGY");

the result of it is

    {
        "visible": false,
        "txID": "0350510c2c89e0dd1cd3fc4817fae30484aeb1a1466e23fac3fb1bafdc94f6dc",
        "raw_data_hex": "0a021b812208e6f9ecbccbfa4dea40c0edc49e85315a5a083612560a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121e0a154144fa2d5a2b5e3ec5692f2aea8afbe0a2921889641080ade204180170e098c19e8531",
        "raw_data": {
            "contract": [
                {
                    "parameter": {
                        "value": {
                            "owner_address": "4144fa2d5a2b5e3ec5692f2aea8afbe0a292188964",
                            "frozen_balance": 10000000,
                            "resource": "ENERGY"
                        },
                        "type_url": "type.googleapis.com/protocol.FreezeBalanceV2Contract"
                    },
                    "type": "FreezeBalanceV2Contract"
                }
            ],
            "ref_block_bytes": "1b81",
            "ref_block_hash": "e6f9ecbccbfa4dea",
            "expiration": 1685033400000,
            "timestamp": 1685033340000
        }
    }

but transaction 0350510c2c89e0dd1cd3fc4817fae30484aeb1a1466e23fac3fb1bafdc94f6dc doesn't exist on the shasta chain. My testing wallet is https://shasta.tronscan.org/#/address/TGFveiYX79EQ4ZwPQF9av8GNExdYnG2sMv (you can see Stake 2.0 transaction, it was manually created on tronscan)

start940315 commented 1 year ago

You just create a transaction, you need to sign and broadcast your transaction so it will be shown on chain.

const signedTransaction = await tronWeb.trx.sign(result);
const result2 = await tronWeb.trx.sendRawTransaction(signedTransaction);
dappd commented 1 year ago

ahhh, I see, my bad. I was using methods from trx domain and they already sign and broadcast, so I was confused. Thanks