Skip to content

Commit 4e42158

Browse files
[SDK] Handle Hedera native currency decimals for smart wallet calls (#6969)
1 parent 5a069fe commit 4e42158

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
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/extensions/erc721/read/getNFT.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
5858
includeOwner: true,
5959
});
6060
expect(nft.metadata.name).toBe("Doodle #1");
61-
expect(nft.owner).toBe("0xbE9936FCFC50666f5425FDE4A9decC59cEF73b24");
61+
expect(nft.owner).toBeDefined();
6262
expect(nft).toMatchInlineSnapshot(`
6363
{
6464
"chainId": 1,
@@ -92,7 +92,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
9292
"name": "Doodle #1",
9393
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
9494
},
95-
"owner": "0xbE9936FCFC50666f5425FDE4A9decC59cEF73b24",
95+
"owner": "0x620b70123fB810F6C653DA7644b5dD0b6312e4D8",
9696
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
9797
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
9898
"type": "ERC721",

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)