near-api-js 7.0.2 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -107
- package/lib/accounts/account.d.ts +47 -40
- package/lib/accounts/account.js +47 -40
- package/lib/accounts/typed_contract.d.ts +5 -11
- package/lib/accounts/typed_contract.js +2 -1
- package/lib/providers/failover-rpc-provider.d.ts +0 -1
- package/lib/providers/failover-rpc-provider.js +0 -1
- package/lib/providers/json-rpc-provider.d.ts +0 -1
- package/lib/providers/json-rpc-provider.js +0 -1
- package/lib/rpc/types.gen.d.ts +6 -8
- package/lib/tokens/ft/index.d.ts +3 -3
- package/lib/tokens/ft/index.js +3 -3
- package/lib/transactions/action_creators.d.ts +5 -4
- package/lib/transactions/action_creators.js +13 -12
- package/lib/transactions/delegate.d.ts +7 -6
- package/lib/transactions/delegate.js +7 -6
- package/lib/utils/format.d.ts +3 -3
- package/lib/utils/format.js +3 -3
- package/lib/utils/validators.d.ts +6 -6
- package/lib/utils/validators.js +6 -6
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,7 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
NEAR JavaScript API is a complete library to interact with the NEAR blockchain. You can use it in the browser, or in Node.js runtime.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> `near-api-js` is ideal to build backend services, CLIs, and scripts that interact with NEAR. For frontend development please check the official [web login docs](https://docs.near.org/web3-apps/concepts/web-login)
|
|
7
|
+
|
|
8
|
+
## Why near-api-js?
|
|
9
|
+
|
|
10
|
+
**near-api-js v7** is a single package that helps you to easily integrate NEAR blockchain into your JavaScript/TypeScript applications.
|
|
11
|
+
|
|
12
|
+
It includes all the functionality you need, including account management, transaction building, key management, interacting with smart contracts, making RPC calls, and more.
|
|
13
|
+
|
|
14
|
+
- ✅ Simple - just one package
|
|
15
|
+
- ✅ Batteries included - everything you need to build scripts and backend services
|
|
16
|
+
- ✅ Friendly - multiple helpers to make your life easier
|
|
17
|
+
- ✅ Full TypeScript support
|
|
18
|
+
- ✅ Works in browser and Node.js
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
Add `near-api-js` to your project using your favorite package manager:
|
|
6
23
|
|
|
7
24
|
```bash
|
|
8
25
|
npm install near-api-js
|
|
@@ -12,19 +29,78 @@ yarn add near-api-js
|
|
|
12
29
|
pnpm add near-api-js
|
|
13
30
|
```
|
|
14
31
|
|
|
15
|
-
|
|
32
|
+
Start using it!
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
```ts
|
|
35
|
+
import { Account, JsonRpcProvider, teraToGas, KeyPairString, nearToYocto } from "near-api-js";
|
|
18
36
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
// Create a testnet provider
|
|
38
|
+
const provider = new JsonRpcProvider({
|
|
39
|
+
url: "https://test.rpc.fastnear.com",
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// For read only calls, you can use the provider directly
|
|
43
|
+
const messages = await provider.callFunction({
|
|
44
|
+
contractId: 'guestbook.near-examples.testnet',
|
|
45
|
+
method: "get_messages",
|
|
46
|
+
args: {},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(messages);
|
|
50
|
+
|
|
51
|
+
// To modify state, you need an account to sign the transaction
|
|
52
|
+
const accountId: string = 'example.testnet';
|
|
53
|
+
const privateKey = 'ed25519:5nM...' as KeyPairString;
|
|
54
|
+
const account = new Account(accountId, provider, privateKey);
|
|
55
|
+
|
|
56
|
+
// Call the contract
|
|
57
|
+
await account.callFunction({
|
|
58
|
+
contractId: 'guestbook.near-examples.testnet',
|
|
59
|
+
methodName: "add_message",
|
|
60
|
+
args: { text: "Hello!" },
|
|
61
|
+
gas: teraToGas('30'),
|
|
62
|
+
deposit: nearToYocto('0.1'),
|
|
63
|
+
});
|
|
64
|
+
```
|
|
24
65
|
|
|
25
|
-
##
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
- [Learn how to use](https://docs.near.org/tools/near-api) the library in your project
|
|
69
|
+
- See it in action in our [API Examples](https://github.com/near-examples/near-api-examples/tree/main/near-api-js)
|
|
70
|
+
- Read the [TypeDoc API](https://near.github.io/near-api-js/) documentation
|
|
71
|
+
|
|
72
|
+
## Migration from @near-js/* packages
|
|
73
|
+
|
|
74
|
+
Check out the [migration guide](MIGRATION.md) to help you move from the old `@near-js/*` packages to `near-api-js`.
|
|
75
|
+
|
|
76
|
+
## Features
|
|
26
77
|
|
|
27
|
-
|
|
78
|
+
`near-api-js` includes some advanced features to help you build robust applications.
|
|
79
|
+
|
|
80
|
+
### Simple Units Conversions
|
|
81
|
+
|
|
82
|
+
You can easily convert between NEAR and yoctoNEAR, and between gas units:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { nearToYocto, yoctoToNear, teraToGas, gigaToGas } from 'near-api-js';
|
|
86
|
+
|
|
87
|
+
await account.callFunction({
|
|
88
|
+
contractId: 'example.testnet',
|
|
89
|
+
methodName: 'some_method',
|
|
90
|
+
args: {},
|
|
91
|
+
gas: teraToGas('30'), // 30 TeraGas
|
|
92
|
+
deposit: nearToYocto('0.1'), // 0.1 NEAR
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// balance in NEAR with 2 decimals
|
|
96
|
+
const balance = yoctoToNear(await account.getBalance(), 2);
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Parallel Transactions
|
|
101
|
+
`near-api-js` can send transactions in parallel by rotating multiple keys for an account.
|
|
102
|
+
|
|
103
|
+
`nonce` collisions are automatically handled by retrying with incremented nonce.
|
|
28
104
|
|
|
29
105
|
```typescript
|
|
30
106
|
import { Account, actions, JsonRpcProvider, KeyPair, MultiKeySigner } from "near-api-js"
|
|
@@ -80,69 +156,36 @@ const sendNearTokensResults = await Promise.all(transfers)
|
|
|
80
156
|
sendNearTokensResults.forEach(result => console.log(result))
|
|
81
157
|
```
|
|
82
158
|
|
|
83
|
-
###
|
|
159
|
+
### Typescript Support
|
|
160
|
+
|
|
161
|
+
`near-api-js` is written in `TypeScript` and includes full type definitions:
|
|
84
162
|
|
|
85
163
|
```typescript
|
|
86
|
-
import {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
viewMethods: ['get_status'],
|
|
93
|
-
changeMethods: ['set_status'],
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// Call methods
|
|
98
|
-
const status = await contract.get_status();
|
|
99
|
-
await contract.set_status({ message: 'Hello NEAR!' });
|
|
164
|
+
import type {
|
|
165
|
+
AccountView,
|
|
166
|
+
BlockReference,
|
|
167
|
+
Action,
|
|
168
|
+
SignedTransaction
|
|
169
|
+
} from 'near-api-js';
|
|
100
170
|
```
|
|
101
171
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
near-api-js includes all NEAR JavaScript functionality:
|
|
105
|
-
|
|
106
|
-
- **Accounts** - Account management and contract interactions
|
|
107
|
-
- **Crypto** - Key pair generation, signing, and verification
|
|
108
|
-
- **Transactions** - Transaction creation and signing
|
|
109
|
-
- **Providers** - RPC providers with failover support
|
|
110
|
-
- **Keystores** - Secure key storage for browser and Node.js
|
|
111
|
-
- **Signers** - Transaction signing interfaces
|
|
112
|
-
- **Types** - Full TypeScript type definitions
|
|
113
|
-
- **Utils** - Formatting, parsing, and helper functions
|
|
114
|
-
- **Tokens** - FT and NFT standard support
|
|
115
|
-
- **Biometric Auth** - WebAuthn support for passwordless auth
|
|
116
|
-
- **IFrame RPC** - Wallet integration helpers
|
|
172
|
+
### Typed Function Calls
|
|
117
173
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
- [Learn how to use](https://docs.near.org/tools/near-api-js/quick-reference) the library in your project
|
|
121
|
-
- Read the [TypeDoc API](https://near.github.io/near-api-js/) documentation
|
|
122
|
-
- [Cookbook](https://github.com/near/near-api-js/blob/master/packages/cookbook/README.md) with common use cases
|
|
123
|
-
- To quickly get started with integrating NEAR in a _web browser_, read our [Web Frontend integration](https://docs.near.org/develop/integrate/frontend) article
|
|
124
|
-
|
|
125
|
-
## Migration from @near-js/* packages
|
|
174
|
+
You can even type the expected results from contract function calls:
|
|
126
175
|
|
|
127
|
-
If you were previously using individual `@near-js/*` packages, migration is straightforward:
|
|
128
|
-
|
|
129
|
-
**Before:**
|
|
130
176
|
```typescript
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
177
|
+
const provider = new JsonRpcProvider({
|
|
178
|
+
url: "https://test.rpc.fastnear.com",
|
|
179
|
+
});
|
|
180
|
+
const account = new Account("accountId", provider, "privateKey");
|
|
135
181
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
import { Account, KeyPair, JsonRpcProvider } from 'near-api-js';
|
|
182
|
+
await provider.callFunction<T>()
|
|
183
|
+
await account.callFunction<T>()
|
|
139
184
|
```
|
|
140
185
|
|
|
141
|
-
|
|
186
|
+
### Failover RPC Provider
|
|
142
187
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Custom RPC Provider
|
|
188
|
+
You can easily define multiple RPC endpoints to connect to NEAR network, if one fails the next one will be used automatically.
|
|
146
189
|
|
|
147
190
|
```typescript
|
|
148
191
|
import { JsonRpcProvider, FailoverRpcProvider } from 'near-api-js';
|
|
@@ -153,45 +196,37 @@ const provider = new FailoverRpcProvider([
|
|
|
153
196
|
]);
|
|
154
197
|
```
|
|
155
198
|
|
|
156
|
-
### Transaction
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
import {
|
|
160
|
-
actions as actionCreators,
|
|
161
|
-
createTransaction,
|
|
162
|
-
signTransaction
|
|
163
|
-
} from 'near-api-js';
|
|
164
|
-
|
|
165
|
-
const { transfer, functionCall } = actionCreators;
|
|
166
|
-
|
|
167
|
-
const actions = [
|
|
168
|
-
transfer(BigInt('1000000000000000000000000')), // 1 NEAR
|
|
169
|
-
functionCall('method_name', { arg: 'value' }, BigInt('30000000000000'), BigInt('0'))
|
|
170
|
-
];
|
|
171
|
-
|
|
172
|
-
const transaction = createTransaction(
|
|
173
|
-
'sender.near',
|
|
174
|
-
publicKey,
|
|
175
|
-
'receiver.near',
|
|
176
|
-
nonce,
|
|
177
|
-
actions,
|
|
178
|
-
blockHash
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const signedTx = await signTransaction(transaction, signer, 'sender.near', networkId);
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## TypeScript Support
|
|
199
|
+
### Decoupled Transaction Signing
|
|
200
|
+
You can separately build transactions, sign them, and broadcast them to the network.
|
|
185
201
|
|
|
186
|
-
|
|
202
|
+
This is useful in scenarios where signing and sending need to be decoupled, such as offline signing
|
|
187
203
|
|
|
188
204
|
```typescript
|
|
189
|
-
import
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
205
|
+
import { JsonRpcProvider, Account, KeyPairSigner, actions, nearToYocto, KeyPairString } from "near-api-js";
|
|
206
|
+
|
|
207
|
+
const provider = new JsonRpcProvider({
|
|
208
|
+
url: "https://test.rpc.fastnear.com",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// You can create a transaction only knowing the accountId and public key
|
|
212
|
+
const publicKey = '';
|
|
213
|
+
const accountId = '';
|
|
214
|
+
const account = new Account(accountId, provider);
|
|
215
|
+
|
|
216
|
+
const transaction = await account.createTransaction({
|
|
217
|
+
receiverId: "receiver-account.testnet",
|
|
218
|
+
actions: [actions.transfer(nearToYocto("0.1"))],
|
|
219
|
+
publicKey: publicKey
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Whoever holds the private key can sign the transaction
|
|
223
|
+
const signer = KeyPairSigner.fromSecretKey(privateKey as KeyPairString);
|
|
224
|
+
const signResult = await signer.signTransaction(transaction);
|
|
225
|
+
console.log(signResult.signedTransaction);
|
|
226
|
+
|
|
227
|
+
// Anybody can send the signed transaction to the network
|
|
228
|
+
const sendTransactionResult = await provider.sendTransaction(signResult.signedTransaction);
|
|
229
|
+
console.log(sendTransactionResult);
|
|
195
230
|
```
|
|
196
231
|
|
|
197
232
|
## Browser and Node.js Support
|
|
@@ -214,20 +249,12 @@ Contributions are welcome! Please check out the [contributing guidelines](https:
|
|
|
214
249
|
|
|
215
250
|
pnpm -r compile -w
|
|
216
251
|
|
|
217
|
-
### Publish
|
|
218
|
-
|
|
219
|
-
Prepare `dist` version by running:
|
|
220
|
-
|
|
221
|
-
pnpm dist
|
|
222
|
-
|
|
223
252
|
### Integration Test
|
|
224
253
|
|
|
225
|
-
|
|
254
|
+
Simply run:
|
|
226
255
|
|
|
227
256
|
pnpm test
|
|
228
257
|
|
|
229
|
-
Tests use sample contract from `near-hello` npm package, see https://github.com/nearprotocol/near-hello
|
|
230
|
-
|
|
231
258
|
## License
|
|
232
259
|
|
|
233
260
|
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
|
|
@@ -143,9 +143,10 @@ export declare class Account {
|
|
|
143
143
|
/**
|
|
144
144
|
* Create a transaction that can be later signed with a {@link Signer}
|
|
145
145
|
*
|
|
146
|
-
* @param
|
|
147
|
-
* @param
|
|
148
|
-
* @param
|
|
146
|
+
* @param options Transaction options
|
|
147
|
+
* @param options.receiverId Account against which to perform the actions
|
|
148
|
+
* @param options.actions Actions to perform
|
|
149
|
+
* @param options.publicKey The public part of the key that will be used to sign the transaction
|
|
149
150
|
*/
|
|
150
151
|
createTransaction({ receiverId, actions, publicKey }: CreateTransactionArgs): Promise<import("../transactions/schema.js").Transaction>;
|
|
151
152
|
/**
|
|
@@ -155,25 +156,28 @@ export declare class Account {
|
|
|
155
156
|
/**
|
|
156
157
|
* Create a meta transaction ready to be signed by a {@link Signer}
|
|
157
158
|
*
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
159
|
+
* @param options Meta transaction options
|
|
160
|
+
* @param options.receiverId NEAR account receiving the transaction
|
|
161
|
+
* @param options.actions list of actions to perform as part of the meta transaction
|
|
162
|
+
* @param options.blockHeightTtl number of blocks after which a meta transaction will expire if not processed
|
|
161
163
|
*/
|
|
162
164
|
createMetaTransaction({ receiverId, actions, blockHeightTtl, publicKey, }: CreateMetaTransactionArgs): Promise<DelegateAction>;
|
|
163
165
|
/**
|
|
164
166
|
* Create a signed MetaTransaction that can be broadcasted to a relayer
|
|
165
167
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @param
|
|
168
|
+
* @param options Signed meta transaction options
|
|
169
|
+
* @param options.receiverId NEAR account receiving the transaction
|
|
170
|
+
* @param options.actions list of actions to perform as part of the meta transaction
|
|
171
|
+
* @param options.blockHeightTtl number of blocks after which a meta transaction will expire if not processed
|
|
169
172
|
*/
|
|
170
173
|
createSignedMetaTransaction({ receiverId, actions, blockHeightTtl, signer, }: CreateSignedMetaTransactionArgs): Promise<SignDelegateActionReturn>;
|
|
171
174
|
/**
|
|
172
175
|
* Creates a transaction, signs it and broadcast it to the network
|
|
173
176
|
*
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
+
* @param options Sign and send transaction options
|
|
178
|
+
* @param options.receiverId The NEAR account ID of the transaction receiver.
|
|
179
|
+
* @param options.actions The list of actions to be performed in the transaction.
|
|
180
|
+
* @param options.throwOnFailure Whether to throw an error if the transaction fails.
|
|
177
181
|
*
|
|
178
182
|
*/
|
|
179
183
|
signAndSendTransaction({ receiverId, actions, waitUntil, throwOnFailure, signer, retries, }: SignAndSendTransactionArgs): Promise<RpcTransactionResponse>;
|
|
@@ -189,9 +193,10 @@ export declare class Account {
|
|
|
189
193
|
* - The new account ID must end with the current account ID
|
|
190
194
|
* - Example: If your account is `ana.near`, you can create `sub.ana.near`
|
|
191
195
|
*
|
|
192
|
-
* @param
|
|
193
|
-
* @param
|
|
194
|
-
* @param
|
|
196
|
+
* @param options Account creation options
|
|
197
|
+
* @param options.newAccountId the new account to create (e.g. bob.near or sub.ana.near)
|
|
198
|
+
* @param options.publicKey the public part of the key that will control the account
|
|
199
|
+
* @param options.nearToTransfer how much NEAR to transfer to the account in yoctoNEAR (default: 0)
|
|
195
200
|
*
|
|
196
201
|
*/
|
|
197
202
|
createAccount({ newAccountId, publicKey, nearToTransfer }: CreateAccountArgs): Promise<RpcTransactionResponse>;
|
|
@@ -199,9 +204,10 @@ export declare class Account {
|
|
|
199
204
|
* Creates a sub account of this account. For example, if the account is
|
|
200
205
|
* ana.near, you can create sub.ana.near.
|
|
201
206
|
*
|
|
202
|
-
* @param
|
|
203
|
-
* @param
|
|
204
|
-
* @param
|
|
207
|
+
* @param options Sub-account creation options
|
|
208
|
+
* @param options.accountOrPrefix a prefix (e.g. `sub`) or the full sub-account (`sub.ana.near`)
|
|
209
|
+
* @param options.publicKey the public part of the key that will control the account
|
|
210
|
+
* @param options.nearToTransfer how much NEAR to transfer to the account (default: 0)
|
|
205
211
|
*
|
|
206
212
|
*/
|
|
207
213
|
createSubAccount({ accountOrPrefix, publicKey, nearToTransfer }: CreateSubAccountArgs): Promise<RpcTransactionResponse>;
|
|
@@ -260,26 +266,26 @@ export declare class Account {
|
|
|
260
266
|
/**
|
|
261
267
|
* Call a function on a smart contract and return parsed transaction result
|
|
262
268
|
*
|
|
263
|
-
* @param
|
|
264
|
-
* @param
|
|
265
|
-
* @param
|
|
266
|
-
* @param
|
|
267
|
-
* @param
|
|
268
|
-
* @param
|
|
269
|
-
* @param
|
|
269
|
+
* @param params Call function parameters
|
|
270
|
+
* @param params.contractId The contract in which to call the function
|
|
271
|
+
* @param params.methodName The method that will be called
|
|
272
|
+
* @param params.args Arguments, either as a valid JSON Object or a raw Uint8Array
|
|
273
|
+
* @param params.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
|
|
274
|
+
* @param params.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
|
|
275
|
+
* @param params.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
|
|
270
276
|
* @returns
|
|
271
277
|
*/
|
|
272
278
|
callFunction<T extends SerializedReturnValue>(params: CallFunctionArgs): Promise<T>;
|
|
273
279
|
/**
|
|
274
280
|
* Call a function on a smart contract and return raw transaction outcome
|
|
275
281
|
*
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @param
|
|
279
|
-
* @param
|
|
280
|
-
* @param
|
|
281
|
-
* @param
|
|
282
|
-
* @param
|
|
282
|
+
* @param params Call function parameters
|
|
283
|
+
* @param params.contractId The contract in which to call the function
|
|
284
|
+
* @param params.methodName The method that will be called
|
|
285
|
+
* @param params.args Arguments, either as a valid JSON Object or a raw Uint8Array
|
|
286
|
+
* @param params.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
|
|
287
|
+
* @param params.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
|
|
288
|
+
* @param params.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
|
|
283
289
|
*/
|
|
284
290
|
callFunctionRaw({ contractId, methodName, args, deposit, gas, waitUntil, }: CallFunctionArgs): Promise<RpcTransactionResponse>;
|
|
285
291
|
/**
|
|
@@ -287,11 +293,11 @@ export declare class Account {
|
|
|
287
293
|
*
|
|
288
294
|
* @deprecated This method is deprecated and will be removed in future versions. Please use `signMessage` from `near-api-js/nep413` to sign NEP-413 messages.
|
|
289
295
|
*
|
|
290
|
-
* @param
|
|
291
|
-
* @param
|
|
292
|
-
* @param
|
|
293
|
-
* @param
|
|
294
|
-
* @param
|
|
296
|
+
* @param args Nep413 message signing arguments
|
|
297
|
+
* @param args.message The message to be signed (e.g. "authenticating")
|
|
298
|
+
* @param args.recipient Who will receive the message (e.g. auth.app.com)
|
|
299
|
+
* @param args.nonce A challenge sent by the recipient
|
|
300
|
+
* @param args.callbackUrl (optional) Deprecated parameter used only by browser wallets
|
|
295
301
|
* @returns
|
|
296
302
|
*/
|
|
297
303
|
signNep413Message({ message, recipient, nonce, callbackUrl, }: SignNep413MessageArgs): Promise<SignedMessage>;
|
|
@@ -306,9 +312,10 @@ export declare class Account {
|
|
|
306
312
|
*
|
|
307
313
|
* Supports sending either the native NEAR token or any supported Fungible Token (FT).
|
|
308
314
|
*
|
|
309
|
-
* @param
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
315
|
+
* @param options Transfer options
|
|
316
|
+
* @param options.amount - The amount of tokens to transfer in units (e.g. yoctoNEAR).
|
|
317
|
+
* @param options.receiverId - The NEAR account ID of the receiver.
|
|
318
|
+
* @param options.token - The token to transfer. Defaults to Native NEAR.
|
|
312
319
|
*
|
|
313
320
|
*/
|
|
314
321
|
transfer({ receiverId, amount, token }: TransferArgs): Promise<RpcTransactionResponse>;
|
package/lib/accounts/account.js
CHANGED
|
@@ -133,9 +133,10 @@ export class Account {
|
|
|
133
133
|
/**
|
|
134
134
|
* Create a transaction that can be later signed with a {@link Signer}
|
|
135
135
|
*
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
136
|
+
* @param options Transaction options
|
|
137
|
+
* @param options.receiverId Account against which to perform the actions
|
|
138
|
+
* @param options.actions Actions to perform
|
|
139
|
+
* @param options.publicKey The public part of the key that will be used to sign the transaction
|
|
139
140
|
*/
|
|
140
141
|
async createTransaction({ receiverId, actions, publicKey }) {
|
|
141
142
|
if (!publicKey)
|
|
@@ -169,9 +170,10 @@ export class Account {
|
|
|
169
170
|
/**
|
|
170
171
|
* Create a meta transaction ready to be signed by a {@link Signer}
|
|
171
172
|
*
|
|
172
|
-
* @param
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
173
|
+
* @param options Meta transaction options
|
|
174
|
+
* @param options.receiverId NEAR account receiving the transaction
|
|
175
|
+
* @param options.actions list of actions to perform as part of the meta transaction
|
|
176
|
+
* @param options.blockHeightTtl number of blocks after which a meta transaction will expire if not processed
|
|
175
177
|
*/
|
|
176
178
|
async createMetaTransaction({ receiverId, actions, blockHeightTtl = 200, publicKey, }) {
|
|
177
179
|
if (!publicKey)
|
|
@@ -197,9 +199,10 @@ export class Account {
|
|
|
197
199
|
/**
|
|
198
200
|
* Create a signed MetaTransaction that can be broadcasted to a relayer
|
|
199
201
|
*
|
|
200
|
-
* @param
|
|
201
|
-
* @param
|
|
202
|
-
* @param
|
|
202
|
+
* @param options Signed meta transaction options
|
|
203
|
+
* @param options.receiverId NEAR account receiving the transaction
|
|
204
|
+
* @param options.actions list of actions to perform as part of the meta transaction
|
|
205
|
+
* @param options.blockHeightTtl number of blocks after which a meta transaction will expire if not processed
|
|
203
206
|
*/
|
|
204
207
|
async createSignedMetaTransaction({ receiverId, actions, blockHeightTtl = 200, signer = this.signer, }) {
|
|
205
208
|
if (!signer)
|
|
@@ -215,9 +218,10 @@ export class Account {
|
|
|
215
218
|
/**
|
|
216
219
|
* Creates a transaction, signs it and broadcast it to the network
|
|
217
220
|
*
|
|
218
|
-
* @param
|
|
219
|
-
* @param
|
|
220
|
-
* @param
|
|
221
|
+
* @param options Sign and send transaction options
|
|
222
|
+
* @param options.receiverId The NEAR account ID of the transaction receiver.
|
|
223
|
+
* @param options.actions The list of actions to be performed in the transaction.
|
|
224
|
+
* @param options.throwOnFailure Whether to throw an error if the transaction fails.
|
|
221
225
|
*
|
|
222
226
|
*/
|
|
223
227
|
async signAndSendTransaction({ receiverId, actions, waitUntil = DEFAULT_WAIT_STATUS, throwOnFailure = true, signer = this.signer, retries = 10, }) {
|
|
@@ -282,9 +286,10 @@ export class Account {
|
|
|
282
286
|
* - The new account ID must end with the current account ID
|
|
283
287
|
* - Example: If your account is `ana.near`, you can create `sub.ana.near`
|
|
284
288
|
*
|
|
285
|
-
* @param
|
|
286
|
-
* @param
|
|
287
|
-
* @param
|
|
289
|
+
* @param options Account creation options
|
|
290
|
+
* @param options.newAccountId the new account to create (e.g. bob.near or sub.ana.near)
|
|
291
|
+
* @param options.publicKey the public part of the key that will control the account
|
|
292
|
+
* @param options.nearToTransfer how much NEAR to transfer to the account in yoctoNEAR (default: 0)
|
|
288
293
|
*
|
|
289
294
|
*/
|
|
290
295
|
async createAccount({ newAccountId, publicKey, nearToTransfer = 0n }) {
|
|
@@ -310,9 +315,10 @@ export class Account {
|
|
|
310
315
|
* Creates a sub account of this account. For example, if the account is
|
|
311
316
|
* ana.near, you can create sub.ana.near.
|
|
312
317
|
*
|
|
313
|
-
* @param
|
|
314
|
-
* @param
|
|
315
|
-
* @param
|
|
318
|
+
* @param options Sub-account creation options
|
|
319
|
+
* @param options.accountOrPrefix a prefix (e.g. `sub`) or the full sub-account (`sub.ana.near`)
|
|
320
|
+
* @param options.publicKey the public part of the key that will control the account
|
|
321
|
+
* @param options.nearToTransfer how much NEAR to transfer to the account (default: 0)
|
|
316
322
|
*
|
|
317
323
|
*/
|
|
318
324
|
async createSubAccount({ accountOrPrefix, publicKey, nearToTransfer = 0n }) {
|
|
@@ -421,13 +427,13 @@ export class Account {
|
|
|
421
427
|
/**
|
|
422
428
|
* Call a function on a smart contract and return parsed transaction result
|
|
423
429
|
*
|
|
424
|
-
* @param
|
|
425
|
-
* @param
|
|
426
|
-
* @param
|
|
427
|
-
* @param
|
|
428
|
-
* @param
|
|
429
|
-
* @param
|
|
430
|
-
* @param
|
|
430
|
+
* @param params Call function parameters
|
|
431
|
+
* @param params.contractId The contract in which to call the function
|
|
432
|
+
* @param params.methodName The method that will be called
|
|
433
|
+
* @param params.args Arguments, either as a valid JSON Object or a raw Uint8Array
|
|
434
|
+
* @param params.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
|
|
435
|
+
* @param params.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
|
|
436
|
+
* @param params.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
|
|
431
437
|
* @returns
|
|
432
438
|
*/
|
|
433
439
|
async callFunction(params) {
|
|
@@ -437,13 +443,13 @@ export class Account {
|
|
|
437
443
|
/**
|
|
438
444
|
* Call a function on a smart contract and return raw transaction outcome
|
|
439
445
|
*
|
|
440
|
-
* @param
|
|
441
|
-
* @param
|
|
442
|
-
* @param
|
|
443
|
-
* @param
|
|
444
|
-
* @param
|
|
445
|
-
* @param
|
|
446
|
-
* @param
|
|
446
|
+
* @param params Call function parameters
|
|
447
|
+
* @param params.contractId The contract in which to call the function
|
|
448
|
+
* @param params.methodName The method that will be called
|
|
449
|
+
* @param params.args Arguments, either as a valid JSON Object or a raw Uint8Array
|
|
450
|
+
* @param params.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
|
|
451
|
+
* @param params.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
|
|
452
|
+
* @param params.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
|
|
447
453
|
*/
|
|
448
454
|
async callFunctionRaw({ contractId, methodName, args = {}, deposit = 0n, gas = DEFAULT_FUNCTION_CALL_GAS, waitUntil = DEFAULT_WAIT_STATUS, }) {
|
|
449
455
|
return await this.signAndSendTransaction({
|
|
@@ -457,11 +463,11 @@ export class Account {
|
|
|
457
463
|
*
|
|
458
464
|
* @deprecated This method is deprecated and will be removed in future versions. Please use `signMessage` from `near-api-js/nep413` to sign NEP-413 messages.
|
|
459
465
|
*
|
|
460
|
-
* @param
|
|
461
|
-
* @param
|
|
462
|
-
* @param
|
|
463
|
-
* @param
|
|
464
|
-
* @param
|
|
466
|
+
* @param args Nep413 message signing arguments
|
|
467
|
+
* @param args.message The message to be signed (e.g. "authenticating")
|
|
468
|
+
* @param args.recipient Who will receive the message (e.g. auth.app.com)
|
|
469
|
+
* @param args.nonce A challenge sent by the recipient
|
|
470
|
+
* @param args.callbackUrl (optional) Deprecated parameter used only by browser wallets
|
|
465
471
|
* @returns
|
|
466
472
|
*/
|
|
467
473
|
async signNep413Message({ message, recipient, nonce, callbackUrl, }) {
|
|
@@ -487,9 +493,10 @@ export class Account {
|
|
|
487
493
|
*
|
|
488
494
|
* Supports sending either the native NEAR token or any supported Fungible Token (FT).
|
|
489
495
|
*
|
|
490
|
-
* @param
|
|
491
|
-
* @param
|
|
492
|
-
* @param
|
|
496
|
+
* @param options Transfer options
|
|
497
|
+
* @param options.amount - The amount of tokens to transfer in units (e.g. yoctoNEAR).
|
|
498
|
+
* @param options.receiverId - The NEAR account ID of the receiver.
|
|
499
|
+
* @param options.token - The token to transfer. Defaults to Native NEAR.
|
|
493
500
|
*
|
|
494
501
|
*/
|
|
495
502
|
async transfer({ receiverId, amount, token = NEAR }) {
|
|
@@ -128,15 +128,9 @@ export type ContractReturnType<abi extends AbiRoot, contractId extends string, _
|
|
|
128
128
|
abi: abi;
|
|
129
129
|
contractId: contractId;
|
|
130
130
|
}>;
|
|
131
|
-
export
|
|
132
|
-
abi
|
|
133
|
-
contractId: contractId
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
} ? ViewMethods : never;
|
|
137
|
-
call: ContractReturnType<abi, contractId> extends {
|
|
138
|
-
call: infer CallMethods;
|
|
139
|
-
} ? CallMethods : never;
|
|
140
|
-
constructor({ abi, provider, contractId }: ContractParameters<abi, contractId>);
|
|
141
|
-
}
|
|
131
|
+
export type ContractConstructor = {
|
|
132
|
+
new <const abi extends AbiRoot, contractId extends string>(params: ContractParameters<abi, contractId>): ContractReturnType<abi, contractId>;
|
|
133
|
+
new <const abi extends AbiRoot, contractId extends string>(params: Prettify<Omit<ContractParameters<abi, contractId>, 'abi'>>): Prettify<Omit<ContractReturnType<abi, contractId>, 'abi'>>;
|
|
134
|
+
};
|
|
135
|
+
export declare const Contract: ContractConstructor;
|
|
142
136
|
export {};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
4
|
import validator from 'is-my-json-valid';
|
|
5
5
|
import { ArgumentSchemaError, UnknownArgumentError } from './errors.js';
|
|
6
|
-
|
|
6
|
+
class RawContract {
|
|
7
7
|
constructor({ abi, provider, contractId }) {
|
|
8
8
|
this.contractId = contractId;
|
|
9
9
|
this.abi = abi;
|
|
@@ -66,6 +66,7 @@ export class Contract {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
export const Contract = RawContract;
|
|
69
70
|
function validateArguments(args, abiFunction, abiRoot) {
|
|
70
71
|
if (typeof args !== 'object' || typeof abiFunction.params !== 'object')
|
|
71
72
|
return;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module
|
|
3
|
-
* @description
|
|
4
3
|
* This module contains the {@link FailoverRpcProvider} client class
|
|
5
4
|
* which can be used to interact with multiple [NEAR RPC APIs](https://docs.near.org/api/rpc/introduction).
|
|
6
5
|
* @see {@link "@near-js/types".provider | provider} for a list of request and response types
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module
|
|
3
|
-
* @description
|
|
4
3
|
* This module contains the {@link FailoverRpcProvider} client class
|
|
5
4
|
* which can be used to interact with multiple [NEAR RPC APIs](https://docs.near.org/api/rpc/introduction).
|
|
6
5
|
* @see {@link "@near-js/types".provider | provider} for a list of request and response types
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module
|
|
3
|
-
* @description
|
|
4
3
|
* This module contains the {@link JsonRpcProvider} client class
|
|
5
4
|
* which can be used to interact with the [NEAR RPC API](https://docs.near.org/api/rpc/introduction).
|
|
6
5
|
* @see {@link "@near-js/types".provider | provider} for a list of request and response types
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module
|
|
3
|
-
* @description
|
|
4
3
|
* This module contains the {@link JsonRpcProvider} client class
|
|
5
4
|
* which can be used to interact with the [NEAR RPC API](https://docs.near.org/api/rpc/introduction).
|
|
6
5
|
* @see {@link "@near-js/types".provider | provider} for a list of request and response types
|
package/lib/rpc/types.gen.d.ts
CHANGED
|
@@ -128,9 +128,9 @@ export type AccountDataView = {
|
|
|
128
128
|
*
|
|
129
129
|
* This is a unique, syntactically valid, human-readable account identifier on the NEAR network.
|
|
130
130
|
*
|
|
131
|
-
* [See the crate
|
|
131
|
+
* [See the Rust crate documentation for information about validation.](https://docs.rs/near-account-id/latest/near_account_id/)
|
|
132
132
|
*
|
|
133
|
-
* Also see
|
|
133
|
+
* Also see the error kind documentation.
|
|
134
134
|
*
|
|
135
135
|
* ## Examples
|
|
136
136
|
*
|
|
@@ -4411,10 +4411,9 @@ export type RpcStateChangesError = {
|
|
|
4411
4411
|
/**
|
|
4412
4412
|
* RpcStateChangesInBlockByTypeRequest
|
|
4413
4413
|
*
|
|
4414
|
-
* It is a
|
|
4414
|
+
* It is a serializable view of `StateChangesRequest`.
|
|
4415
4415
|
*
|
|
4416
|
-
*
|
|
4417
|
-
* [`StateChangesRequest`]: ../types/struct.StateChangesRequest.html
|
|
4416
|
+
* See the Rust crate documentation for more information.
|
|
4418
4417
|
*/
|
|
4419
4418
|
export type RpcStateChangesInBlockByTypeRequest = ({
|
|
4420
4419
|
block_id: BlockId;
|
|
@@ -5315,10 +5314,9 @@ export type StateChangeCauseView = {
|
|
|
5315
5314
|
type: 'bandwidth_scheduler_state_update';
|
|
5316
5315
|
};
|
|
5317
5316
|
/**
|
|
5318
|
-
* It is a
|
|
5317
|
+
* It is a serializable view of `StateChangeKind`.
|
|
5319
5318
|
*
|
|
5320
|
-
*
|
|
5321
|
-
* [`StateChangeKind`]: ../types/struct.StateChangeKind.html
|
|
5319
|
+
* See the Rust crate documentation for more information.
|
|
5322
5320
|
*/
|
|
5323
5321
|
export type StateChangeKindView = {
|
|
5324
5322
|
account_id: AccountId;
|
package/lib/tokens/ft/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare abstract class BaseFT {
|
|
|
19
19
|
/**
|
|
20
20
|
* Converts indivisible units to a decimal number (represented as a string)
|
|
21
21
|
*
|
|
22
|
-
* @param
|
|
22
|
+
* @param amount The amount in indivisible units (e.g. "1234")
|
|
23
23
|
* @param precision (optional) number of digits shown to the right of the decimal point - rounded down
|
|
24
24
|
* @returns The amount as a decimal string (e.g. "1.234")
|
|
25
25
|
*/
|
|
@@ -66,10 +66,10 @@ export declare class FungibleToken extends BaseFT {
|
|
|
66
66
|
* Transfer tokens and call a function on the receiver contract,
|
|
67
67
|
* only works if the receiver implements the `ft_on_transfer` method
|
|
68
68
|
*
|
|
69
|
-
* @param param
|
|
69
|
+
* @param param Transfer call parameters
|
|
70
70
|
* @param param.from The Account that will transfer the tokens
|
|
71
71
|
* @param param.receiverId The AccountID that will receive the tokens
|
|
72
|
-
* @param param.
|
|
72
|
+
* @param param.amount The amount of tokens to transfer in the smallest unit
|
|
73
73
|
* @param param.msg The message to send to the `ft_on_transfer` method
|
|
74
74
|
*/
|
|
75
75
|
transferCall({ from, receiverId, amount, msg, }: {
|
package/lib/tokens/ft/index.js
CHANGED
|
@@ -17,7 +17,7 @@ class BaseFT {
|
|
|
17
17
|
/**
|
|
18
18
|
* Converts indivisible units to a decimal number (represented as a string)
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
20
|
+
* @param amount The amount in indivisible units (e.g. "1234")
|
|
21
21
|
* @param precision (optional) number of digits shown to the right of the decimal point - rounded down
|
|
22
22
|
* @returns The amount as a decimal string (e.g. "1.234")
|
|
23
23
|
*/
|
|
@@ -67,10 +67,10 @@ export class FungibleToken extends BaseFT {
|
|
|
67
67
|
* Transfer tokens and call a function on the receiver contract,
|
|
68
68
|
* only works if the receiver implements the `ft_on_transfer` method
|
|
69
69
|
*
|
|
70
|
-
* @param param
|
|
70
|
+
* @param param Transfer call parameters
|
|
71
71
|
* @param param.from The Account that will transfer the tokens
|
|
72
72
|
* @param param.receiverId The AccountID that will receive the tokens
|
|
73
|
-
* @param param.
|
|
73
|
+
* @param param.amount The amount of tokens to transfer in the smallest unit
|
|
74
74
|
* @param param.msg The message to send to the `ft_on_transfer` method
|
|
75
75
|
*/
|
|
76
76
|
async transferCall({ from, receiverId, amount, msg, }) {
|
|
@@ -84,8 +84,9 @@ declare function deleteKey(publicKey: PublicKey): Action;
|
|
|
84
84
|
declare function deleteAccount(beneficiaryId: string): Action;
|
|
85
85
|
/**
|
|
86
86
|
* Creates a new action for a signed delegation, specifying the delegate action and signature.
|
|
87
|
-
* @param
|
|
88
|
-
* @param
|
|
87
|
+
* @param options Signed delegate options
|
|
88
|
+
* @param options.delegateAction The delegate action to be performed.
|
|
89
|
+
* @param options.signature The signature associated with the delegate action.
|
|
89
90
|
* @returns A new action for a signed delegation.
|
|
90
91
|
*/
|
|
91
92
|
declare function signedDelegate({ delegateAction, signature, }: {
|
|
@@ -98,13 +99,13 @@ declare function signedDelegate({ delegateAction, signature, }: {
|
|
|
98
99
|
* @param deployMode The mode to deploy global contract (CodeHash or AccountId).
|
|
99
100
|
* @returns A new action for deploying a global contract.
|
|
100
101
|
*/
|
|
101
|
-
declare function deployGlobalContract(code: Uint8Array,
|
|
102
|
+
declare function deployGlobalContract(code: Uint8Array, deployMode: 'codeHash' | 'accountId'): Action;
|
|
102
103
|
/**
|
|
103
104
|
* Creates a new action for using a previously deployed global contract.
|
|
104
105
|
* @param contractIdentifier The global contract identifier (hash or account id).
|
|
105
106
|
* @returns A new action for using a global contract.
|
|
106
107
|
*/
|
|
107
|
-
declare function useGlobalContract(
|
|
108
|
+
declare function useGlobalContract(contractIdentifier: {
|
|
108
109
|
accountId: string;
|
|
109
110
|
} | {
|
|
110
111
|
codeHash: string | Uint8Array;
|
|
@@ -136,8 +136,9 @@ function deleteAccount(beneficiaryId) {
|
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Creates a new action for a signed delegation, specifying the delegate action and signature.
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
139
|
+
* @param options Signed delegate options
|
|
140
|
+
* @param options.delegateAction The delegate action to be performed.
|
|
141
|
+
* @param options.signature The signature associated with the delegate action.
|
|
141
142
|
* @returns A new action for a signed delegation.
|
|
142
143
|
*/
|
|
143
144
|
function signedDelegate({ delegateAction, signature, }) {
|
|
@@ -151,28 +152,28 @@ function signedDelegate({ delegateAction, signature, }) {
|
|
|
151
152
|
* @param deployMode The mode to deploy global contract (CodeHash or AccountId).
|
|
152
153
|
* @returns A new action for deploying a global contract.
|
|
153
154
|
*/
|
|
154
|
-
function deployGlobalContract(code,
|
|
155
|
-
const
|
|
155
|
+
function deployGlobalContract(code, deployMode) {
|
|
156
|
+
const mode = deployMode === 'codeHash'
|
|
156
157
|
? new GlobalContractDeployMode({ CodeHash: null })
|
|
157
158
|
: new GlobalContractDeployMode({ AccountId: null });
|
|
158
|
-
return new Action({ deployGlobalContract: new DeployGlobalContract({ code, deployMode }) });
|
|
159
|
+
return new Action({ deployGlobalContract: new DeployGlobalContract({ code, deployMode: mode }) });
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
161
162
|
* Creates a new action for using a previously deployed global contract.
|
|
162
163
|
* @param contractIdentifier The global contract identifier (hash or account id).
|
|
163
164
|
* @returns A new action for using a global contract.
|
|
164
165
|
*/
|
|
165
|
-
function useGlobalContract(
|
|
166
|
-
const
|
|
166
|
+
function useGlobalContract(contractIdentifier) {
|
|
167
|
+
const identifier = 'accountId' in contractIdentifier
|
|
167
168
|
? new GlobalContractIdentifier({
|
|
168
|
-
AccountId:
|
|
169
|
+
AccountId: contractIdentifier.accountId,
|
|
169
170
|
})
|
|
170
171
|
: new GlobalContractIdentifier({
|
|
171
|
-
CodeHash: typeof
|
|
172
|
-
? Buffer.from(
|
|
173
|
-
:
|
|
172
|
+
CodeHash: typeof contractIdentifier.codeHash === 'string'
|
|
173
|
+
? Buffer.from(contractIdentifier.codeHash, 'hex')
|
|
174
|
+
: contractIdentifier.codeHash,
|
|
174
175
|
});
|
|
175
|
-
return new Action({ useGlobalContract: new UseGlobalContract({ contractIdentifier }) });
|
|
176
|
+
return new Action({ useGlobalContract: new UseGlobalContract({ contractIdentifier: identifier }) });
|
|
176
177
|
}
|
|
177
178
|
export const actions = {
|
|
178
179
|
addFullAccessKey,
|
|
@@ -18,11 +18,12 @@ export declare class DelegateAction {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Compose a delegate action for inclusion with a meta transaction signed on the sender's behalf
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
21
|
+
* @param options Delegate action options
|
|
22
|
+
* @param options.actions The set of actions to be included in the meta transaction
|
|
23
|
+
* @param options.maxBlockHeight The maximum block height for which this action can be executed as part of a transaction
|
|
24
|
+
* @param options.nonce Current nonce on the access key used to sign the delegate action
|
|
25
|
+
* @param options.publicKey Public key for the access key used to sign the delegate action
|
|
26
|
+
* @param options.receiverId Account ID for the intended receiver of the meta transaction
|
|
27
|
+
* @param options.senderId Account ID for the intended signer of the delegate action
|
|
27
28
|
*/
|
|
28
29
|
export declare function buildDelegateAction({ actions, maxBlockHeight, nonce, publicKey, receiverId, senderId, }: DelegateAction): DelegateAction;
|
|
@@ -13,12 +13,13 @@ export class DelegateAction {
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Compose a delegate action for inclusion with a meta transaction signed on the sender's behalf
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
16
|
+
* @param options Delegate action options
|
|
17
|
+
* @param options.actions The set of actions to be included in the meta transaction
|
|
18
|
+
* @param options.maxBlockHeight The maximum block height for which this action can be executed as part of a transaction
|
|
19
|
+
* @param options.nonce Current nonce on the access key used to sign the delegate action
|
|
20
|
+
* @param options.publicKey Public key for the access key used to sign the delegate action
|
|
21
|
+
* @param options.receiverId Account ID for the intended receiver of the meta transaction
|
|
22
|
+
* @param options.senderId Account ID for the intended signer of the delegate action
|
|
22
23
|
*/
|
|
23
24
|
export function buildDelegateAction({ actions, maxBlockHeight, nonce, publicKey, receiverId, senderId, }) {
|
|
24
25
|
return new DelegateAction({
|
package/lib/utils/format.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const NEAR_NOMINATION_EXP = 24;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const NEAR_NOMINATION: bigint;
|
|
10
10
|
/**
|
|
11
|
-
* @deprecated use {@link yoctoToNear} instead.
|
|
11
|
+
* @deprecated use {@link units!yoctoToNear} from 'near-api-js' instead.
|
|
12
12
|
*
|
|
13
13
|
* Convert account balance value from internal indivisible units to NEAR. 1 NEAR is defined by {@link NEAR_NOMINATION}.
|
|
14
14
|
* Effectively this divides given amount by {@link NEAR_NOMINATION}.
|
|
@@ -19,12 +19,12 @@ export declare const NEAR_NOMINATION: bigint;
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function formatNearAmount(balance: string | number | bigint, fracDigits?: number): string;
|
|
21
21
|
/**
|
|
22
|
-
* @deprecated use {@link nearToYocto} instead.
|
|
22
|
+
* @deprecated use {@link units!nearToYocto} from 'near-api-js' instead.
|
|
23
23
|
*
|
|
24
24
|
* Convert human readable NEAR amount to internal indivisible units.
|
|
25
25
|
* Effectively this multiplies given amount by {@link NEAR_NOMINATION}.
|
|
26
26
|
*
|
|
27
|
-
* @param
|
|
27
|
+
* @param amount decimal string (potentially fractional) denominated in NEAR.
|
|
28
28
|
* @returns The parsed yoctoⓃ amount
|
|
29
29
|
* @throws {Error} if the amount is empty or invalid
|
|
30
30
|
*/
|
package/lib/utils/format.js
CHANGED
|
@@ -14,7 +14,7 @@ for (let i = 0, offset = 5n; i < NEAR_NOMINATION_EXP; i++, offset = offset * BN1
|
|
|
14
14
|
ROUNDING_OFFSETS[i] = offset;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* @deprecated use {@link yoctoToNear} instead.
|
|
17
|
+
* @deprecated use {@link units!yoctoToNear} from 'near-api-js' instead.
|
|
18
18
|
*
|
|
19
19
|
* Convert account balance value from internal indivisible units to NEAR. 1 NEAR is defined by {@link NEAR_NOMINATION}.
|
|
20
20
|
* Effectively this divides given amount by {@link NEAR_NOMINATION}.
|
|
@@ -41,12 +41,12 @@ export function formatNearAmount(balance, fracDigits = NEAR_NOMINATION_EXP) {
|
|
|
41
41
|
return trimTrailingZeroes(`${formatWithCommas(wholeStr)}.${fractionStr}`);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* @deprecated use {@link nearToYocto} instead.
|
|
44
|
+
* @deprecated use {@link units!nearToYocto} from 'near-api-js' instead.
|
|
45
45
|
*
|
|
46
46
|
* Convert human readable NEAR amount to internal indivisible units.
|
|
47
47
|
* Effectively this multiplies given amount by {@link NEAR_NOMINATION}.
|
|
48
48
|
*
|
|
49
|
-
* @param
|
|
49
|
+
* @param amount decimal string (potentially fractional) denominated in NEAR.
|
|
50
50
|
* @returns The parsed yoctoⓃ amount
|
|
51
51
|
* @throws {Error} if the amount is empty or invalid
|
|
52
52
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { CurrentEpochValidatorInfo, NextEpochValidatorInfo } from '../types/index.js';
|
|
2
2
|
/** Finds seat price given validators stakes and number of seats.
|
|
3
3
|
* Calculation follow the spec: https://nomicon.io/Economics/README.html#validator-selection
|
|
4
|
-
* @param validators
|
|
5
|
-
* @param maxNumberOfSeats
|
|
6
|
-
* @param minimumStakeRatio
|
|
7
|
-
* @param protocolVersion
|
|
4
|
+
* @param validators current or next epoch validators.
|
|
5
|
+
* @param maxNumberOfSeats maximum number of seats in the network.
|
|
6
|
+
* @param minimumStakeRatio minimum stake ratio
|
|
7
|
+
* @param protocolVersion version of the protocol from genesis config
|
|
8
8
|
*/
|
|
9
9
|
export declare function findSeatPrice(validators: (CurrentEpochValidatorInfo | NextEpochValidatorInfo)[], maxNumberOfSeats: number, minimumStakeRatio: number[], protocolVersion?: number): bigint;
|
|
10
10
|
export interface ChangedValidatorInfo {
|
|
@@ -18,7 +18,7 @@ export interface EpochValidatorsDiff {
|
|
|
18
18
|
}
|
|
19
19
|
/** Diff validators between current and next epoch.
|
|
20
20
|
* Returns additions, subtractions and changes to validator set.
|
|
21
|
-
* @param currentValidators
|
|
22
|
-
* @param nextValidators
|
|
21
|
+
* @param currentValidators list of current validators.
|
|
22
|
+
* @param nextValidators list of next validators.
|
|
23
23
|
*/
|
|
24
24
|
export declare function diffEpochValidators(currentValidators: CurrentEpochValidatorInfo[], nextValidators: NextEpochValidatorInfo[]): EpochValidatorsDiff;
|
package/lib/utils/validators.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { sortBigIntAsc } from './utils.js';
|
|
2
2
|
/** Finds seat price given validators stakes and number of seats.
|
|
3
3
|
* Calculation follow the spec: https://nomicon.io/Economics/README.html#validator-selection
|
|
4
|
-
* @param validators
|
|
5
|
-
* @param maxNumberOfSeats
|
|
6
|
-
* @param minimumStakeRatio
|
|
7
|
-
* @param protocolVersion
|
|
4
|
+
* @param validators current or next epoch validators.
|
|
5
|
+
* @param maxNumberOfSeats maximum number of seats in the network.
|
|
6
|
+
* @param minimumStakeRatio minimum stake ratio
|
|
7
|
+
* @param protocolVersion version of the protocol from genesis config
|
|
8
8
|
*/
|
|
9
9
|
export function findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio, protocolVersion) {
|
|
10
10
|
if (protocolVersion && protocolVersion < 49) {
|
|
@@ -63,8 +63,8 @@ function findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumSt
|
|
|
63
63
|
}
|
|
64
64
|
/** Diff validators between current and next epoch.
|
|
65
65
|
* Returns additions, subtractions and changes to validator set.
|
|
66
|
-
* @param currentValidators
|
|
67
|
-
* @param nextValidators
|
|
66
|
+
* @param currentValidators list of current validators.
|
|
67
|
+
* @param nextValidators list of next validators.
|
|
68
68
|
*/
|
|
69
69
|
export function diffEpochValidators(currentValidators, nextValidators) {
|
|
70
70
|
const validatorsMap = new Map();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "near-api-js",
|
|
3
3
|
"description": "JavaScript library to interact with NEAR Protocol via RPC API",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/near/near-api-js.git"
|
|
@@ -85,12 +85,12 @@
|
|
|
85
85
|
"near-sandbox": "0.0.18"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
|
-
"compile": "tsc -p ./tsconfig.json",
|
|
88
|
+
"compile": "tsc -p ./tsconfig.build.json",
|
|
89
89
|
"dev": "pnpm compile -w",
|
|
90
90
|
"prebuild": "pnpm clean",
|
|
91
|
-
"build": "tsc -p ./tsconfig.json",
|
|
91
|
+
"build": "tsc -p ./tsconfig.build.json",
|
|
92
92
|
"test": "vitest run test",
|
|
93
|
-
"typecheck": "tsc --noEmit -p ./tsconfig.
|
|
93
|
+
"typecheck": "tsc --noEmit -p ./tsconfig.json",
|
|
94
94
|
"lint": "biome check",
|
|
95
95
|
"prefuzz": "pnpm build",
|
|
96
96
|
"fuzz": "jsfuzz test/fuzz/borsh-roundtrip.js test/fuzz/corpus/",
|