Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/twenty-bees-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Update createToken to return a prepared transaction
2 changes: 1 addition & 1 deletion packages/thirdweb/src/exports/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export {
DEFAULT_DEVELOPER_ADDRESS,
DEFAULT_DEVELOPER_REWARD_BPS,
} from "../tokens/constants.js";
export { createToken } from "../tokens/create-token.js";
export { createToken, prepareCreateToken } from "../tokens/create-token.js";
export { distributeToken } from "../tokens/distribute-token.js";
export {
getDeployedContractFactory,
Expand Down
36 changes: 36 additions & 0 deletions packages/thirdweb/src/tokens/create-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,39 @@ export async function createToken(options: CreateTokenOptions) {

return decodedEvent[0]?.args.asset;
}

export async function prepareCreateToken(options: CreateTokenOptions) {
const { client, params, account, launchConfig } = options;

const creator = params.owner || account.address;
const encodedInitData = await encodeInitParams({
client,
creator,
params,
});

const salt: Hex = generateSalt(options.salt || bytesToHex(randomBytes(31)));

const entrypoint = await getDeployedEntrypointERC20(options);

let hookData: Hex = "0x";
let contractId = padHex(toHex("ERC20Asset"), { size: 32 });
if (launchConfig?.kind === "pool") {
hookData = encodePoolConfig(launchConfig.config);
contractId = padHex(toHex("ERC20Asset_Pool"), { size: 32 });
}

const transaction = createById({
contract: entrypoint,
contractId,
params: {
data: encodedInitData,
hookData,
developer: options.developerAddress || DEFAULT_DEVELOPER_ADDRESS,
salt,
},
creator,
});

return transaction;
}
Comment on lines +66 to +100
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 20, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify types and upstream call sites: remove account from CreateTokenOptions and require TokenParams.owner

The code still references account and treats params.owner as optional. Ensure:

  • CreateTokenOptions excludes account
  • TokenParams.owner is required
  • predict-address.ts and any other helpers derive creator from params.owner only

Run this script to locate and update remaining references:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Check destructuring of options for account in token flows"
rg -n -C3 --type=ts '(const|let)\s*\{\s*[^}]*account[^}]*\}\s*=\s*options' packages/thirdweb/src | sed -n '1,200p'

echo "Where is CreateTokenOptions defined/used?"
rg -n -C3 --type=ts '\b(CreateTokenOptions|TokenParams)\b' packages/thirdweb/src | sed -n '1,200p'

echo "Find uses of account in predict-address and token creation"
rg -n -C3 --type=ts '\baccount\b' packages/thirdweb/src/tokens/predict-address.ts packages/thirdweb/src/tokens/create-token.ts || true

echo "Find createToken call sites to assess breakage from return type change"
rg -n -C3 --type=ts '\bcreateToken\s*\(' | sed -n '1,200p'

Length of output: 28489


Ensure token creation only uses params.owner and remove account from options

Please make the following mandatory updates:

• Update types
– in packages/thirdweb/src/tokens/types.ts:
• Remove the inherited account field from CreateTokenOptions (no longer extend ClientAndChainAndAccount)
• Add a required owner: string property to TokenParams

• Update token-flow implementations
packages/thirdweb/src/tokens/create-token.ts (createToken & prepareCreateToken):
• Drop account from the options destructuring
• Replace params.owner || account.address with params.owner
packages/thirdweb/src/tokens/predict-address.ts:
• Drop account from the options destructuring
• Derive creator = params.owner only

• Fix all upstream call sites for createToken and predictAddress (e.g. in apps/dashboard/.../create-token-page-impl.tsx):
– Remove passing account
– Ensure callers supply params.owner

These changes are breaking—please update types, implementations, and all call sites accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CodeRabbit don't tell me to make "mandatory" updates. You don't understand this code or its business context in the slightest. Know your place.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gregfromstl I apologize for being overly prescriptive in my previous comment. You're absolutely right - I don't have the full business context behind these design decisions, and I should have asked clarifying questions rather than making assumptions about what changes were needed.

Thank you for the feedback on my approach. I'll focus on asking questions and providing observations rather than directing what should be done, especially when I lack the domain knowledge you have as the author.

      (\   /)
     ( ._. )
    o_(")(")

2 changes: 1 addition & 1 deletion packages/thirdweb/src/tokens/predict-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import type { CreateTokenOptions } from "./types.js";

export async function predictAddress(options: CreateTokenOptions) {
const { client, account, params, launchConfig } = options;
const { client, params, launchConfig, account } = options;

const creator = params.owner || account.address;
const encodedInitData = await encodeInitParams({
Expand Down
Loading