Skip to content

Commit c2a5f82

Browse files
authored
Merge pull request #1827 from near/fix-contract-constructor-interface
fix: fix bug where `Contract` couldn't be constructed without `abi`
2 parents 9e825ea + 8443635 commit c2a5f82

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.changeset/modern-terms-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"near-api-js": patch
3+
---
4+
5+
Fix the bug where `Contract` couldn't be constructed without `abi`

src/accounts/typed_contract.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,17 @@ export type ContractReturnType<
276276
: {}) & { abi: abi; contractId: contractId }
277277
>;
278278

279-
export class Contract<const abi extends AbiRoot, contractId extends string> {
279+
export type ContractConstructor = {
280+
new <const abi extends AbiRoot, contractId extends string>(
281+
params: ContractParameters<abi, contractId>
282+
): ContractReturnType<abi, contractId>;
283+
284+
new <const abi extends AbiRoot, contractId extends string>(
285+
params: Prettify<Omit<ContractParameters<abi, contractId>, 'abi'>>
286+
): Prettify<Omit<ContractReturnType<abi, contractId>, 'abi'>>;
287+
};
288+
289+
class RawContract<const abi extends AbiRoot, contractId extends string> {
280290
abi?: abi;
281291
contractId: contractId;
282292

@@ -378,6 +388,8 @@ export class Contract<const abi extends AbiRoot, contractId extends string> {
378388
}
379389
}
380390

391+
export const Contract = RawContract as ContractConstructor;
392+
381393
function validateArguments(args: object, abiFunction: AbiFunction, abiRoot: AbiRoot) {
382394
if (typeof args !== 'object' || typeof abiFunction.params !== 'object') return;
383395

test/contracts/guestbook/abi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AbiRoot } from 'near-api-js';
1+
import type { AbiRoot } from '../../../src';
22

33
export const abi = {
44
schema_version: '0.4.0',

0 commit comments

Comments
 (0)