Skip to content

Commit 280d161

Browse files
committed
Use toHex(0n) in translatePayment for better clarity
- Use bigint internally (0n) and convert to hex at JSON-RPC boundary - Add comment explaining the conversion for JSON-RPC compatibility - This follows modern best practices while maintaining compatibility
1 parent 948e5e4 commit 280d161

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

packages/account-sdk/src/interface/payment/pay.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('pay', () => {
4343
{
4444
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
4545
data: '0xabcdef',
46-
value: 0n,
46+
value: '0x0',
4747
},
4848
],
4949
capabilities: {},
@@ -103,7 +103,7 @@ describe('pay', () => {
103103
{
104104
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
105105
data: '0xabcdef',
106-
value: 0n,
106+
value: '0x0',
107107
},
108108
],
109109
capabilities: {},
@@ -148,7 +148,7 @@ describe('pay', () => {
148148
{
149149
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
150150
data: '0xabcdef',
151-
value: 0n,
151+
value: '0x0',
152152
},
153153
],
154154
capabilities: {},
@@ -234,7 +234,7 @@ describe('pay', () => {
234234
{
235235
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
236236
data: '0xabcdef',
237-
value: 0n,
237+
value: '0x0',
238238
},
239239
],
240240
capabilities: {},
@@ -271,7 +271,7 @@ describe('pay', () => {
271271
{
272272
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
273273
data: '0xabcdef',
274-
value: 0n,
274+
value: '0x0',
275275
},
276276
],
277277
capabilities: {},
@@ -352,7 +352,7 @@ describe('pay', () => {
352352
{
353353
to: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
354354
data: '0xabcdef',
355-
value: 0n,
355+
value: '0x0',
356356
},
357357
],
358358
capabilities: {
@@ -417,7 +417,7 @@ describe('pay', () => {
417417
{
418418
to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
419419
data: '0xabcdef',
420-
value: 0n,
420+
value: '0x0',
421421
},
422422
],
423423
capabilities: {

packages/account-sdk/src/interface/payment/utils/translatePayment.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { describe, expect, it } from 'vitest';
22
import { CHAIN_IDS, TOKENS } from '../constants.js';
33
import type { PayerInfo } from '../types.js';
44
import {
5-
buildSendCallsRequest,
6-
encodeTransferCall,
7-
translatePaymentToSendCalls,
5+
buildSendCallsRequest,
6+
encodeTransferCall,
7+
translatePaymentToSendCalls,
88
} from './translatePayment.js';
99

1010
describe('translatePayment', () => {

packages/account-sdk/src/interface/payment/utils/translatePayment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { encodeFunctionData, parseUnits, type Address, type Hex } from 'viem';
1+
import { encodeFunctionData, parseUnits, toHex, type Address, type Hex } from 'viem';
22
import { CHAIN_IDS, ERC20_TRANSFER_ABI, TOKENS } from '../constants.js';
33
import type { PayerInfo } from '../types.js';
44

@@ -35,7 +35,7 @@ export function buildSendCallsRequest(transferData: Hex, testnet: boolean, payer
3535
const call = {
3636
to: usdcAddress as Address,
3737
data: transferData,
38-
value: '0x0' as Hex, // No ETH value for ERC20 transfer
38+
value: toHex(0n), // No ETH value for ERC20 transfer
3939
};
4040

4141
// Build the capabilities object

0 commit comments

Comments
 (0)