diff --git a/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js b/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js index f46c056e..26c4c7e0 100644 --- a/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js +++ b/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js @@ -1728,6 +1728,11 @@ describe('Test with mock', () => { }, ]) }) + + it('should return empty array as response if request is an empty array', async () => { + const emptyBatch = rpc.createBatchRequest([]) + expect(await emptyBatch.exec()).toEqual([]) + }) }) }) diff --git a/packages/ckb-sdk-rpc/src/index.ts b/packages/ckb-sdk-rpc/src/index.ts index 37d5c946..410d712f 100644 --- a/packages/ckb-sdk-rpc/src/index.ts +++ b/packages/ckb-sdk-rpc/src/index.ts @@ -101,6 +101,10 @@ class CKBRPC extends Base { } }) + if (!payload.length) { + return [] + } + const batchRes = await axios({ method: 'POST', headers: { 'content-type': 'application/json' },