Skip to content

Commit 24981a7

Browse files
fix: respect raw accountSalt passed as hex (#4965)
1 parent f2c40bd commit 24981a7

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.changeset/stupid-waves-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Respect raw accountSalt passed as hex

packages/thirdweb/src/wallets/smart/lib/calls.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ThirdwebContract } from "../../../contract/contract.js";
22
import { prepareContractCall } from "../../../transaction/prepare-contract-call.js";
33
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
44
import { readContract } from "../../../transaction/read-contract.js";
5-
import { stringToHex } from "../../../utils/encoding/hex.js";
5+
import { isHex, stringToHex } from "../../../utils/encoding/hex.js";
66
import type { SendTransactionOption } from "../../interfaces/wallet.js";
77

88
/**
@@ -48,11 +48,14 @@ export async function predictAddress(args: {
4848
"Account address is required to predict the smart wallet address.",
4949
);
5050
}
51-
const extraData = stringToHex(accountSalt ?? "");
51+
const saltHex =
52+
accountSalt && isHex(accountSalt)
53+
? accountSalt
54+
: stringToHex(accountSalt ?? "");
5255
return readContract({
5356
contract: factoryContract,
5457
method: "function getAddress(address, bytes) returns (address)",
55-
params: [adminAddress, extraData],
58+
params: [adminAddress, saltHex],
5659
});
5760
}
5861

@@ -76,10 +79,14 @@ export function prepareCreateAccount(args: {
7679
if (createAccount) {
7780
return createAccount(factoryContract);
7881
}
82+
const saltHex =
83+
accountSalt && isHex(accountSalt)
84+
? accountSalt
85+
: stringToHex(accountSalt ?? "");
7986
return prepareContractCall({
8087
contract: factoryContract,
8188
method: "function createAccount(address, bytes) returns (address)",
82-
params: [adminAddress, stringToHex(accountSalt ?? "")],
89+
params: [adminAddress, saltHex],
8390
});
8491
}
8592

0 commit comments

Comments
 (0)