Skip to content

Commit a520b20

Browse files
[SDK] Handle Hedera native currency decimals for smart wallet calls
1 parent 5a069fe commit a520b20

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

.changeset/chubby-aliens-film.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+
Handle hedera native currency decimal values for smart wallet calls

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,15 @@ export function prepareExecute(args: {
181181
if (execute) {
182182
return execute(accountContract, transaction);
183183
}
184+
let value = transaction.value || 0n;
185+
// special handling of hedera chains, decimals for native value is 8 instead of 18 when passed as contract params
186+
if (transaction.chainId === 295 || transaction.chainId === 296) {
187+
value = value / BigInt(10 ** 10);
188+
}
184189
return prepareContractCall({
185190
contract: accountContract,
186191
method: "function execute(address, uint256, bytes)",
187-
params: [
188-
transaction.to || "",
189-
transaction.value || 0n,
190-
transaction.data || "0x",
191-
],
192+
params: [transaction.to || "", value, transaction.data || "0x"],
192193
// if gas is specified for the inner tx, use that and add 21k for the execute call on the account contract
193194
// this avoids another estimateGas call when bundling the userOp
194195
// and also allows for passing custom gas limits for the inner tx
@@ -215,12 +216,18 @@ export function prepareBatchExecute(args: {
215216
if (executeBatch) {
216217
return executeBatch(accountContract, transactions);
217218
}
219+
let values = transactions.map((tx) => tx.value || 0n);
220+
const chainId = transactions[0]?.chainId;
221+
// special handling of hedera chains, decimals for native value is 8 instead of 18 when passed as contract params
222+
if (chainId === 295 || chainId === 296) {
223+
values = values.map((value) => value / BigInt(10 ** 10));
224+
}
218225
return prepareContractCall({
219226
contract: accountContract,
220227
method: "function executeBatch(address[], uint256[], bytes[])",
221228
params: [
222229
transactions.map((tx) => tx.to || ""),
223-
transactions.map((tx) => tx.value || 0n),
230+
values,
224231
transactions.map((tx) => tx.data || "0x"),
225232
],
226233
});

0 commit comments

Comments
 (0)