Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/portal/src/app/typescript/v5/auth/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ import { privateKeyToAccount } from "thirdweb/wallets";

const privateKey = process.env.THIRDWEB_PRIVATE_KEY;
const thirdwebClient = createThirdwebClient({
secretKey: process.env.THIRDWEB_SECRET_KEY;
secretKey: process.env.THIRDWEB_SECRET_KEY,
});

const auth = createAuth({
domain: "localhost:3000",
client: thirdwebClient,
adminAccount: privateKeyToAccount({client, privateKey})
adminAccount: privateKeyToAccount({ client: thirdwebClient, privateKey }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '1,140p' apps/portal/src/app/typescript/v5/auth/page.mdx && printf '\n---\n' && rg -n "privateKeyToAccount|PRIVATE_KEY|process\.env" apps/portal/src/app -S

Repository: thirdweb-dev/js

Length of output: 9328


🌐 Web query:

thirdweb privateKeyToAccount undefined replace source code

💡 Result:

If you are encountering an undefined error when using privateKeyToAccount in the thirdweb TypeScript SDK, please note that the function has been renamed to privateKeyAccount in newer versions of the SDK [1]. To resolve this, update your import and usage as follows: 1. Update your import: import { privateKeyAccount } from "thirdweb/wallets"; 2. Update your implementation: const account = privateKeyAccount({ client, privateKey: process.env.PRIVATE_KEY as string, }); If you were previously relying on the source code implementation of privateKeyToAccount, it is worth noting that the internal implementation automatically handles prefixing the private key with 0x [2]: const privateKey = 0x${options.privateKey.replace(/^0x/, "")} satisfies Hex; If you continue to face runtime or build errors (such as issues in specific environments like Expo), ensure your SDK is updated to the latest version [3], as bug fixes related to import/build errors are frequently released [3]. Top results: [3] #3299 [2] https://cdn.jsdelivr.net/npm/thirdweb@5.116.1/src/wallets/private-key.ts [1] https://portal.thirdweb.com/typescript/v5/account-abstraction/get-started

Citations:


🏁 Script executed:

python3 - <<'PY'
import urllib.request
url = "https://cdn.jsdelivr.net/npm/thirdweb@5.116.1/src/wallets/private-key.ts"
with urllib.request.urlopen(url, timeout=20) as r:
    text = r.read().decode("utf-8")
for i, line in enumerate(text.splitlines(), 1):
    if "replace(" in line or "export function privateKey" in line or "privateKeyToAccount" in line:
        start = max(1, i-3)
        end = min(len(text.splitlines()), i+5)
        for j in range(start, end+1):
            print(f"{j}:{text.splitlines()[j-1]}")
        print("---")
PY

Repository: thirdweb-dev/js

Length of output: 2747


Guard THIRDWEB_PRIVATE_KEY before constructing the account. privateKeyToAccount dereferences privateKey immediately, so this example will throw on startup if the env var is missing. Add an explicit check before the call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/portal/src/app/typescript/v5/auth/page.mdx` at line 51, Guard the
THIRDWEB_PRIVATE_KEY value before the privateKeyToAccount call in the
adminAccount configuration. Validate that the environment-derived privateKey is
present, and fail explicitly before constructing the account when it is missing;
preserve the existing account creation path for a provided key.

});

// 1. generate a login payload for a client on the server side
Expand Down
5 changes: 3 additions & 2 deletions apps/portal/src/app/typescript/v5/getting-started/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import { inAppWallet } from "thirdweb/wallets"
// create or access a wallet
const wallet = inAppWallet();
const account = await wallet.connect({
client: TEST_CLIENT,
client,
strategy: "backend", // we use backend strategy to generate a wallet from a secret key
walletSecret: "my-test-wallet-secret", // use this secret to access the same wallet across multiple scripts
});
Expand All @@ -102,7 +102,8 @@ import { getWalletBalance } from "thirdweb/wallets";

// Get the balance of the account
const balance = await getWalletBalance({
account,
client,
address: account.address,
chain: sepolia,
});
console.log("Balance:", balance.displayValue, balance.symbol);
Expand Down
Loading