Why do we need private key to connect to TronGrid API?

I’m looking at the code to transfer tokens via TronGrid and it shows the below.

  const tronWeb = new TronWeb({
    fullHost: url,
    headers: { "TRON-PRO-API-KEY": AppKey },
    privateKey: privateKey,
  });

Is this the private key to my wallet?

16 Likes

yes, in case you need to sign txs

5 Likes

Ok, I’m assuming this is optional. Anyway, thank you for your reply.

5 Likes

Do you know how to use tron in react

1 Like

We are using tronweb and tronlink to connect our react frontend to Tron blockchain

1 Like

Ok. I have used metamask BTTC testnet in react project

1 Like

I am very interested to learn how you use tronlink in react frontend, I am trying to write an API in python to send tron usdt in very safe method offline and just broadcast it online

will appreciate if you give me more information

3 Likes

Ohhh it is too hard but interesting

2 Likes

I will not advice to use that API as it’s never a good ideea to send PK to tge network you can use the tronweb instance from tronlink check out the docs.

You are looking to sign a transaction and then brodcast the transaction. There is tronpy check that out. I did this with TronGrid api on my project OnChain Vision.

Basically what I did was.
1.Query the contract
2.Get the function selector
3. Call the TriggerSmartContract this will get un unsign transaction
4.Sign the transaction(I use WalletConnect but you can do that manually)
5. Brodcast sign transction

And all of this with my primary key staying local on my computer.

This is just an API format do not use it for an app but it s usefull if you want to sign automatically your own transaction.

I done the sign ing with my project from HackaTRON 3 Tron Direct Debit. I think the source code is open but if anything contact me it s a little mess but will give you some perspective on how to do it or check out other projects.

Existe alguma forma de reduzir o gas cobrado?

const result = await contract.transfer(
address,
value //amount
).send({
feeLimit: 100000000
})

Great and useful topic, thanks

@qwerty389 you need to pass private key to sign transactions. And its optional. If you are intending to read only from tron nodes then you don’t need to pass this.

@hazerakhatun In case of react and assume tronlink is already installed. Then you can access tronweb by using window.tronweb. It does has same functions as tronweb from sdk.