near.view and near.call works well for quick scripts, but they are “stringly typed.” If you misspell a method name or pass the wrong arguments, you won’t know until your code crashes at runtime.
near-kit allows you to define a TypeScript interface for your contract. This gives you:
- Autocomplete for method names.
- Type Checking for arguments and return values.
- Inline Documentation (if you add JSDoc comments).
1. Define the Interface
You define a type that passes a generic object toContract. This object must have view and call properties describing your methods.
2. Create the Proxy
Use thenear.contract<T>() method to create a typed proxy for a specific contract ID.
3. Use it!
You can now access methods directly under.view and .call.
Calling Views
Arguments are passed as the first parameter.Calling Change Methods
Change methods take two arguments:- Args: The arguments for the contract function.
- Options: (Optional) Gas and Attached Deposit.