Skip to content

Commit bb48f08

Browse files
authored
Merge pull request #191 from etherspot/fix/update-transaction-kit-2.0.3
fix/update-transaction-kit-2.0.3
2 parents e6d1839 + 59f92d4 commit bb48f08

8 files changed

Lines changed: 115 additions & 62 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [2.0.3] - 2025-08-22
4+
5+
### Added Changes
6+
7+
- `chainId` is mandatory in the `transaction()` method.
8+
- For `send` and `estimate`, the `etherspotModularSdk` is initialized using the transaction's `chainId` rather than the provider's `chainId`.
39
## [2.0.2] - 2025-07-24
410

511
### Added Changes

__tests__/EtherspotTransactionKit.test.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ describe('EtherspotTransactionKit', () => {
193193

194194
it('should use default values for optional parameters', () => {
195195
const txParams = {
196+
chainId: 1,
196197
to: '0x1234567890123456789012345678901234567890',
197198
};
198199

@@ -206,15 +207,15 @@ describe('EtherspotTransactionKit', () => {
206207

207208
it('should throw error for missing to address', () => {
208209
expect(() => {
209-
transactionKit.transaction({ to: '' });
210+
transactionKit.transaction({ chainId: 1, to: '' });
210211
}).toThrow('transaction(): to is required.');
211212
});
212213

213214
it('should throw error for invalid to address', () => {
214215
(isAddress as unknown as jest.Mock).mockReturnValue(false);
215216

216217
expect(() => {
217-
transactionKit.transaction({ to: 'invalid-address' });
218+
transactionKit.transaction({ chainId: 1, to: 'invalid-address' });
218219
}).toThrow(`transaction(): 'invalid-address' is not a valid address.`);
219220
});
220221

@@ -230,6 +231,7 @@ describe('EtherspotTransactionKit', () => {
230231
it('should throw error for invalid value', () => {
231232
expect(() => {
232233
transactionKit.transaction({
234+
chainId: 1,
233235
to: '0x1234567890123456789012345678901234567890',
234236
value: 'invalid',
235237
});
@@ -241,6 +243,7 @@ describe('EtherspotTransactionKit', () => {
241243
it('should throw error for negative value', () => {
242244
expect(() => {
243245
transactionKit.transaction({
246+
chainId: 1,
244247
to: '0x1234567890123456789012345678901234567890',
245248
value: '-1',
246249
});
@@ -251,6 +254,7 @@ describe('EtherspotTransactionKit', () => {
251254

252255
it('should accept bigint value', () => {
253256
const txParams = {
257+
chainId: 1,
254258
to: '0x1234567890123456789012345678901234567890',
255259
value: BigInt(1000),
256260
};
@@ -266,6 +270,7 @@ describe('EtherspotTransactionKit', () => {
266270
describe('name', () => {
267271
beforeEach(() => {
268272
transactionKit.transaction({
273+
chainId: 1,
269274
to: '0x1234567890123456789012345678901234567890',
270275
});
271276
});
@@ -319,6 +324,7 @@ describe('EtherspotTransactionKit', () => {
319324
describe('remove', () => {
320325
it('should remove named transaction', () => {
321326
transactionKit.transaction({
327+
chainId: 1,
322328
to: '0x1234567890123456789012345678901234567890',
323329
});
324330
transactionKit.name({ transactionName: 'test' });
@@ -341,6 +347,7 @@ describe('EtherspotTransactionKit', () => {
341347

342348
it('should throw error if transaction not named', () => {
343349
transactionKit.transaction({
350+
chainId: 1,
344351
to: '0x1234567890123456789012345678901234567890',
345352
});
346353

@@ -355,6 +362,7 @@ describe('EtherspotTransactionKit', () => {
355362
describe('update', () => {
356363
beforeEach(() => {
357364
transactionKit.transaction({
365+
chainId: 1,
358366
to: '0x1234567890123456789012345678901234567890',
359367
});
360368
transactionKit.name({ transactionName: 'test' });
@@ -380,6 +388,7 @@ describe('EtherspotTransactionKit', () => {
380388
describe('estimate', () => {
381389
beforeEach(() => {
382390
transactionKit.transaction({
391+
chainId: 1,
383392
to: '0x1234567890123456789012345678901234567890',
384393
value: '1000000000000000000',
385394
data: '0x1234',
@@ -504,6 +513,7 @@ describe('EtherspotTransactionKit', () => {
504513
it('should allow transaction with value = 0 and data = 0x', async () => {
505514
const kit = new EtherspotTransactionKit(mockConfig);
506515
kit.transaction({
516+
chainId: 1,
507517
to: '0x1234567890123456789012345678901234567890',
508518
value: '0',
509519
data: '0x',
@@ -547,6 +557,7 @@ describe('EtherspotTransactionKit', () => {
547557
describe('send', () => {
548558
beforeEach(() => {
549559
transactionKit.transaction({
560+
chainId: 1,
550561
to: '0x1234567890123456789012345678901234567890',
551562
value: '1000000000000000000',
552563
data: '0x1234',
@@ -658,6 +669,7 @@ describe('EtherspotTransactionKit', () => {
658669

659670
it('should allow sending transaction with value = 0 and data = 0x', async () => {
660671
transactionKit.transaction({
672+
chainId: 1,
661673
to: '0x1234567890123456789012345678901234567890',
662674
value: '0',
663675
data: '0x',
@@ -743,6 +755,7 @@ describe('EtherspotTransactionKit', () => {
743755

744756
it('should return state with transaction', () => {
745757
transactionKit.transaction({
758+
chainId: 1,
746759
to: '0x1234567890123456789012345678901234567890',
747760
value: '1000000000000000000',
748761
});
@@ -779,6 +792,7 @@ describe('EtherspotTransactionKit', () => {
779792
expect(() => {
780793
debugKit.setDebugMode(true);
781794
debugKit.transaction({
795+
chainId: 1,
782796
to: '0x1234567890123456789012345678901234567890',
783797
});
784798
debugKit.name({ transactionName: 'debug-tx' });
@@ -828,6 +842,7 @@ describe('EtherspotTransactionKit', () => {
828842
it('should reset all state', () => {
829843
// Set up some state
830844
transactionKit.transaction({
845+
chainId: 1,
831846
to: '0x1234567890123456789012345678901234567890',
832847
});
833848
transactionKit.name({ transactionName: 'test' });
@@ -870,6 +885,7 @@ describe('EtherspotTransactionKit', () => {
870885
describe('State management during operations', () => {
871886
beforeEach(() => {
872887
transactionKit.transaction({
888+
chainId: 1,
873889
to: '0x1234567890123456789012345678901234567890',
874890
value: '1000000000000000000',
875891
});
@@ -929,23 +945,24 @@ describe('EtherspotTransactionKit', () => {
929945
});
930946

931947
describe('Provider integration', () => {
932-
it('should handle provider chain ID changes', () => {
948+
it('should use explicit chainId from transaction call', () => {
933949
mockProvider.getChainId.mockReturnValue(5);
934950

935951
transactionKit.transaction({
952+
chainId: 1,
936953
to: '0x1234567890123456789012345678901234567890',
937954
});
938955

939956
const state = transactionKit.getState();
940957
expect(state.workingTransaction?.chainId).toBe(1);
941958

942-
// Test with no explicit chainId
943959
transactionKit.transaction({
960+
chainId: 137,
944961
to: '0x1234567890123456789012345678901234567890',
945962
value: '1',
946963
});
947964
const state2 = transactionKit.getState();
948-
expect(state2.workingTransaction?.chainId).toBe(1); // Should use default
965+
expect(state2.workingTransaction?.chainId).toBe(137);
949966
});
950967

951968
it('should handle SDK instance errors gracefully', async () => {
@@ -972,12 +989,14 @@ describe('Batch operations', () => {
972989
mockSdk.send.mockReset();
973990
mockSdk.totalGasEstimated.mockReset();
974991
transactionKit.transaction({
992+
chainId: 1,
975993
to: '0x1111111111111111111111111111111111111111',
976994
value: '1000000000000000000',
977995
});
978996
transactionKit.name({ transactionName: 'tx1' });
979997
transactionKit.addToBatch({ batchName: 'batch1' });
980998
transactionKit.transaction({
999+
chainId: 1,
9811000
to: '0x2222222222222222222222222222222222222222',
9821001
value: '2000000000000000000',
9831002
});

example/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const App = () => {
3939
action: async (logAndUpdateState: (msg: string) => void) => {
4040
try {
4141
kit.transaction({
42+
chainId: 137,
4243
to: '0x000000000000000000000000000000000000dead',
4344
value: '1000000000000000000',
4445
});
@@ -57,6 +58,7 @@ const App = () => {
5758
transactionName: 'tx1',
5859
}) as INamedTransaction;
5960
named.transaction({
61+
chainId: 137,
6062
to: '0x000000000000000000000000000000000000beef',
6163
value: '2000000000000000000',
6264
});
@@ -86,6 +88,7 @@ const App = () => {
8688
action: async (logAndUpdateState: (msg: string) => void) => {
8789
try {
8890
kit.transaction({
91+
chainId: 137,
8992
to: '0x000000000000000000000000000000000000cafe',
9093
value: '3000000000000000000',
9194
});
@@ -104,6 +107,7 @@ const App = () => {
104107
action: async (logAndUpdateState: (msg: string) => void) => {
105108
try {
106109
kit.transaction({
110+
chainId: 137,
107111
to: '0x000000000000000000000000000000000000babe',
108112
value: '4000000000000000000',
109113
});
@@ -252,6 +256,7 @@ const App = () => {
252256
action: async (logAndUpdateState: (msg: string) => void) => {
253257
try {
254258
kit.transaction({
259+
chainId: 137,
255260
to: '0x000000000000000000000000000000000000f00d',
256261
value: '5000000000000000000',
257262
});
@@ -272,6 +277,7 @@ const App = () => {
272277
try {
273278
// Ensure tx3 is in batch1
274279
kit.transaction({
280+
chainId: 137,
275281
to: '0x000000000000000000000000000000000000babe',
276282
value: '4000000000000000000',
277283
});
@@ -295,6 +301,7 @@ const App = () => {
295301
try {
296302
// Add tx5 to batch2
297303
kit.transaction({
304+
chainId: 137,
298305
to: '0x000000000000000000000000000000000000c0de',
299306
value: '6000000000000000000',
300307
});
@@ -304,6 +311,7 @@ const App = () => {
304311
named.addToBatch({ batchName: 'batch2' });
305312
// Add tx6 to batch2
306313
kit.transaction({
314+
chainId: 137,
307315
to: '0x000000000000000000000000000000000000c0fe',
308316
value: '7000000000000000000',
309317
});
@@ -327,6 +335,7 @@ const App = () => {
327335
try {
328336
// Ensure tx3 is in batch1
329337
kit.transaction({
338+
chainId: 137,
330339
to: '0x000000000000000000000000000000000000babe',
331340
value: '4000000000000000000',
332341
});
@@ -336,6 +345,7 @@ const App = () => {
336345
named.addToBatch({ batchName: 'batch1' });
337346
// Now update tx3 in batch1
338347
named.transaction({
348+
chainId: 137,
339349
to: '0x000000000000000000000000000000000000feed',
340350
value: '8880000000000000000',
341351
});
@@ -353,6 +363,7 @@ const App = () => {
353363
action: async (logAndUpdateState: (msg: string) => void) => {
354364
try {
355365
kit.transaction({
366+
chainId: 137,
356367
to: '0x000000000000000000000000000000000000aabb',
357368
value: '1000000000000000000',
358369
});
@@ -389,6 +400,7 @@ const App = () => {
389400
action: async (logAndUpdateState: (msg: string) => void) => {
390401
try {
391402
kit.transaction({
403+
chainId: 137,
392404
to: '0x000000000000000000000000000000000000cafe',
393405
value: '123',
394406
});
@@ -423,7 +435,7 @@ const App = () => {
423435
label: 'Add Transaction with Invalid Address',
424436
action: async (logAndUpdateState: (msg: string) => void) => {
425437
try {
426-
kit.transaction({ to: 'not-an-address', value: '1' });
438+
kit.transaction({ chainId: 137, to: 'not-an-address', value: '1' });
427439
logAndUpdateState('Should not see this.');
428440
} catch (e) {
429441
logAndUpdateState('Error: ' + (e as Error).message);
@@ -435,6 +447,7 @@ const App = () => {
435447
action: async (logAndUpdateState: (msg: string) => void) => {
436448
try {
437449
kit.transaction({
450+
chainId: 137,
438451
to: '0x000000000000000000000000000000000000dead',
439452
value: '-1',
440453
});
@@ -474,6 +487,7 @@ const App = () => {
474487
try {
475488
// Create empty batchD by adding and removing a tx
476489
kit.transaction({
490+
chainId: 137,
477491
to: '0x000000000000000000000000000000000000dede',
478492
value: '1',
479493
});
@@ -512,6 +526,7 @@ const App = () => {
512526
try {
513527
// Add tx10 to batchE
514528
kit.transaction({
529+
chainId: 137,
515530
to: '0x000000000000000000000000000000000000eeee',
516531
value: '1',
517532
});
@@ -533,6 +548,7 @@ const App = () => {
533548
action: async (logAndUpdateState: (msg: string) => void) => {
534549
try {
535550
kit.transaction({
551+
chainId: 137,
536552
to: '0x000000000000000000000000000000000000f0f0',
537553
value: '1',
538554
});
@@ -548,6 +564,7 @@ const App = () => {
548564
action: async (logAndUpdateState: (msg: string) => void) => {
549565
try {
550566
kit.transaction({
567+
chainId: 137,
551568
to: '0x000000000000000000000000000000000000f1f1',
552569
value: '1',
553570
});
@@ -556,6 +573,7 @@ const App = () => {
556573
}) as INamedTransaction;
557574
named.addToBatch({ batchName: 'batchF' });
558575
named.transaction({
576+
chainId: 137,
559577
to: '0x000000000000000000000000000000000000f2f2',
560578
value: '2',
561579
});

0 commit comments

Comments
 (0)