Skip to content

Commit db1a561

Browse files
committed
fix(sdk): hedera network claim
1 parent 0998fc7 commit db1a561

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

packages/thirdweb/src/contract/deployment/zksync/zkDeployCreate2Factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function zkDeployCreate2Factory(
4141
privateKey: PUBLISHED_PRIVATE_KEY,
4242
});
4343

44-
const valueToSend = toWei("0.01");
44+
const valueToSend = toWei("0.01", options.chain);
4545
const balance = await getWalletBalance({
4646
address: create2Signer.address,
4747
chain: options.chain,

packages/thirdweb/src/extensions/erc20/write/deposit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export type DepositParams =
2929
*/
3030
export function deposit(options: BaseTransactionOptions<DepositParams>) {
3131
const value =
32-
"amountWei" in options ? options.amountWei : toWei(options.amount);
32+
"amountWei" in options
33+
? options.amountWei
34+
: toWei(options.amount, options.contract.chain);
3335
return prepareContractCall({
3436
contract: options.contract,
3537
method: [FN_SELECTOR, [], []] as const,

packages/thirdweb/src/react/core/hooks/wallets/useSendToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function useSendToken(client: ThirdwebClient) {
7979
chain: activeChain,
8080
client,
8181
to,
82-
value: toWei(amount),
82+
value: toWei(amount, activeChain),
8383
});
8484

8585
await sendTransaction({

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export function TransferConfirmationScreen(
217217
client,
218218
chain,
219219
to: receiverAddress,
220-
value: toWei(tokenAmount),
220+
value: toWei(tokenAmount, chain),
221221
})
222222
: transfer({
223223
contract: getContract({

packages/thirdweb/src/utils/units.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Chain } from "../chains/types.js";
2+
13
/**
24
* Converts a given number of units to a string representation with a specified number of decimal places.
35
* @param units - The number of units to convert.
@@ -125,10 +127,22 @@ export function toUnits(tokens: string, decimals: number): bigint {
125127
* toWei('1')
126128
* // 1000000000000000000n
127129
* ```
130+
*
131+
* For chains with varying decimals, you can provide the chain.
132+
* ```ts
133+
* import { toWei } from "thirdweb/utils";
134+
* toWei('1', defineChain(295))
135+
* // 10000000n
136+
* ```
128137
* @utils
129138
*/
130-
export function toWei(tokens: string) {
131-
return toUnits(tokens, 18);
139+
export function toWei(tokens: string, chain?: Chain) {
140+
switch (chain?.id) {
141+
case 295:
142+
return toUnits(tokens, 8);
143+
default:
144+
return toUnits(tokens, 18);
145+
}
132146
}
133147

134148
/**

0 commit comments

Comments
 (0)