--- title: setPrivateKey description: "Sets the private key on a TronWeb instance for address derivation and signing; since 6.4.0 a leading 0x prefix is stripped." keywords: ["setprivatekey", "utils", "private key", "signing", "default address", "tronweb"] --- # setPrivateKey Set a private key used with the TronWeb instance, used for obtaining the address, signing transactions, and getting balances. > ❗️WARNING : > > Do not use this with any web/user facing TronWeb instances. This will leak the private key. ## Usage ```JavaScript TronWeb.setPrivateKey(private key); ``` ## Parameters | Parameter | Description | Data Type | | ----------- | ------------------------- | --------- | | private key | The private key to be set. **Since 6.4.0** a leading `0x` prefix is accepted and stripped before storing. | String | ## Returns No return value ## Example ```JavaScript tronWeb.setPrivateKey('AD71****7509'); tronWeb.defaultPrivateKey // output-start 'AD71****7509' // output-end // Since 6.4.0 a leading `0x` prefix is accepted and stripped before storing tronWeb.setPrivateKey('0xAD71****7509'); tronWeb.defaultPrivateKey // output-start 'AD71****7509' // output-end ```