near-api-js 7.0.1 → 7.0.2
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/lib/tokens/ft/index.d.ts +11 -11
- package/lib/tokens/ft/index.js +12 -5
- package/lib/tokens/mt/index.d.ts +6 -6
- package/lib/tokens/mt/index.js +14 -6
- package/lib/tokens/nft/index.d.ts +2 -2
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.js +0 -1
- package/package.json +1 -1
- package/lib/types/accounts.d.ts +0 -20
- package/lib/types/accounts.js +0 -1
package/lib/tokens/ft/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Account } from '../../accounts/account.js';
|
|
2
2
|
interface FTMetadata {
|
|
3
3
|
spec?: string;
|
|
4
4
|
name: string;
|
|
@@ -30,7 +30,7 @@ declare abstract class BaseFT {
|
|
|
30
30
|
* @param account The account to get the balance of
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
|
-
abstract getBalance(account:
|
|
33
|
+
abstract getBalance(account: Account): Promise<bigint>;
|
|
34
34
|
/**
|
|
35
35
|
* Transfer tokens from one account to another
|
|
36
36
|
*
|
|
@@ -40,28 +40,28 @@ declare abstract class BaseFT {
|
|
|
40
40
|
* @param param.amount The amount of tokens to transfer in the smallest unit
|
|
41
41
|
*/
|
|
42
42
|
abstract transfer({ from, receiverId, amount, }: {
|
|
43
|
-
from:
|
|
43
|
+
from: Account;
|
|
44
44
|
receiverId: string;
|
|
45
45
|
amount: string | number | bigint;
|
|
46
46
|
}): Promise<any>;
|
|
47
47
|
}
|
|
48
48
|
export declare class NativeToken extends BaseFT {
|
|
49
49
|
transfer({ from, receiverId, amount, }: {
|
|
50
|
-
from:
|
|
50
|
+
from: Account;
|
|
51
51
|
receiverId: string;
|
|
52
52
|
amount: string | number | bigint;
|
|
53
53
|
}): Promise<any>;
|
|
54
|
-
getBalance(account:
|
|
54
|
+
getBalance(account: Account): Promise<bigint>;
|
|
55
55
|
}
|
|
56
56
|
export declare class FungibleToken extends BaseFT {
|
|
57
57
|
readonly accountId: string;
|
|
58
58
|
constructor(accountId: string, metadata: FTMetadata);
|
|
59
59
|
transfer({ from, receiverId, amount, }: {
|
|
60
|
-
from:
|
|
60
|
+
from: Account;
|
|
61
61
|
receiverId: string;
|
|
62
62
|
amount: string | number | bigint;
|
|
63
63
|
}): Promise<any>;
|
|
64
|
-
getBalance(account:
|
|
64
|
+
getBalance(account: Account): Promise<bigint>;
|
|
65
65
|
/**
|
|
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
|
|
@@ -73,7 +73,7 @@ export declare class FungibleToken extends BaseFT {
|
|
|
73
73
|
* @param param.msg The message to send to the `ft_on_transfer` method
|
|
74
74
|
*/
|
|
75
75
|
transferCall({ from, receiverId, amount, msg, }: {
|
|
76
|
-
from:
|
|
76
|
+
from: Account;
|
|
77
77
|
receiverId: string;
|
|
78
78
|
amount: bigint;
|
|
79
79
|
msg: string;
|
|
@@ -86,8 +86,8 @@ export declare class FungibleToken extends BaseFT {
|
|
|
86
86
|
* @param param.fundingAccount The Account that will fund the registration
|
|
87
87
|
*/
|
|
88
88
|
registerAccount({ accountIdToRegister, fundingAccount, }: {
|
|
89
|
-
accountIdToRegister:
|
|
90
|
-
fundingAccount:
|
|
89
|
+
accountIdToRegister: string;
|
|
90
|
+
fundingAccount: Account;
|
|
91
91
|
}): Promise<any>;
|
|
92
92
|
/**
|
|
93
93
|
* Unregister an account from the fungible token contract by paying a storage deposit
|
|
@@ -97,7 +97,7 @@ export declare class FungibleToken extends BaseFT {
|
|
|
97
97
|
* @param param.force Whether to remove the account without claiming the storage deposit
|
|
98
98
|
*/
|
|
99
99
|
unregisterAccount({ account, force }: {
|
|
100
|
-
account:
|
|
100
|
+
account: Account;
|
|
101
101
|
force: boolean;
|
|
102
102
|
}): Promise<any>;
|
|
103
103
|
}
|
package/lib/tokens/ft/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { actions } from '../../transactions/action_creators.js';
|
|
1
2
|
import { formatAmount, parseAmount } from './format.js';
|
|
2
3
|
class BaseFT {
|
|
3
4
|
constructor(metadata) {
|
|
@@ -28,7 +29,7 @@ export class NativeToken extends BaseFT {
|
|
|
28
29
|
async transfer({ from, receiverId, amount, }) {
|
|
29
30
|
return from.signAndSendTransaction({
|
|
30
31
|
receiverId,
|
|
31
|
-
actions: [
|
|
32
|
+
actions: [actions.transfer(BigInt(amount))],
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
async getBalance(account) {
|
|
@@ -55,8 +56,10 @@ export class FungibleToken extends BaseFT {
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
async getBalance(account) {
|
|
58
|
-
const balance = await account.provider.callFunction(
|
|
59
|
-
|
|
59
|
+
const balance = await account.provider.callFunction({
|
|
60
|
+
contractId: this.accountId,
|
|
61
|
+
method: 'ft_balance_of',
|
|
62
|
+
args: { account_id: account.accountId },
|
|
60
63
|
});
|
|
61
64
|
return BigInt(balance);
|
|
62
65
|
}
|
|
@@ -91,8 +94,12 @@ export class FungibleToken extends BaseFT {
|
|
|
91
94
|
* @param param.fundingAccount The Account that will fund the registration
|
|
92
95
|
*/
|
|
93
96
|
async registerAccount({ accountIdToRegister, fundingAccount, }) {
|
|
94
|
-
const
|
|
95
|
-
|
|
97
|
+
const bounds = (await fundingAccount.provider.callFunction({
|
|
98
|
+
contractId: this.accountId,
|
|
99
|
+
method: 'storage_balance_bounds',
|
|
100
|
+
args: {},
|
|
101
|
+
}));
|
|
102
|
+
const requiredDeposit = bounds.min;
|
|
96
103
|
return fundingAccount.callFunction({
|
|
97
104
|
contractId: this.accountId,
|
|
98
105
|
methodName: 'storage_deposit',
|
package/lib/tokens/mt/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Account } from '../../accounts/account.js';
|
|
2
2
|
export declare class MultiTokenContract {
|
|
3
3
|
readonly accountId: string;
|
|
4
4
|
constructor(accountId: string);
|
|
@@ -9,7 +9,7 @@ export declare class MultiTokenContract {
|
|
|
9
9
|
* @param tokenId The token to retrieve the balance from
|
|
10
10
|
* @returns The balance in the smallest unit as bigint
|
|
11
11
|
*/
|
|
12
|
-
getBalance(account:
|
|
12
|
+
getBalance(account: Account, tokenId: string): Promise<bigint>;
|
|
13
13
|
/**
|
|
14
14
|
* Get the available balances of an account for the given tokens in indivisible units
|
|
15
15
|
*
|
|
@@ -17,7 +17,7 @@ export declare class MultiTokenContract {
|
|
|
17
17
|
* @param tokenIds The tokens to retrieve the balances from
|
|
18
18
|
* @returns The balances in the smallest unit as bigint[] matching the order of tokenIds
|
|
19
19
|
*/
|
|
20
|
-
getBatchedBalance(account:
|
|
20
|
+
getBatchedBalance(account: Account, tokenIds: string[]): Promise<bigint[]>;
|
|
21
21
|
/**
|
|
22
22
|
* Transfer tokens from one account to another
|
|
23
23
|
*
|
|
@@ -30,7 +30,7 @@ export declare class MultiTokenContract {
|
|
|
30
30
|
* @param param.memo Optional memo for indexing
|
|
31
31
|
*/
|
|
32
32
|
transfer({ from, receiverId, tokenId, amount, approval, memo, }: {
|
|
33
|
-
from:
|
|
33
|
+
from: Account;
|
|
34
34
|
receiverId: string;
|
|
35
35
|
tokenId: string;
|
|
36
36
|
amount: string | number | bigint;
|
|
@@ -51,7 +51,7 @@ export declare class MultiTokenContract {
|
|
|
51
51
|
* @param param.memo Optional memo for indexing
|
|
52
52
|
*/
|
|
53
53
|
transferCall({ from, receiverId, tokenId, amount, msg, approval, memo, }: {
|
|
54
|
-
from:
|
|
54
|
+
from: Account;
|
|
55
55
|
receiverId: string;
|
|
56
56
|
tokenId: string;
|
|
57
57
|
amount: bigint;
|
|
@@ -71,7 +71,7 @@ export declare class MultiTokenContract {
|
|
|
71
71
|
* @param param.memo Optional memo for indexing
|
|
72
72
|
*/
|
|
73
73
|
batchTransfer({ from, receiverId, tokenIds, amounts, approvals, memo, }: {
|
|
74
|
-
from:
|
|
74
|
+
from: Account;
|
|
75
75
|
receiverId: string;
|
|
76
76
|
tokenIds: string[];
|
|
77
77
|
amounts: Array<string | number | bigint>;
|
package/lib/tokens/mt/index.js
CHANGED
|
@@ -10,9 +10,13 @@ export class MultiTokenContract {
|
|
|
10
10
|
* @returns The balance in the smallest unit as bigint
|
|
11
11
|
*/
|
|
12
12
|
async getBalance(account, tokenId) {
|
|
13
|
-
const balance = await account.provider.callFunction(
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const balance = await account.provider.callFunction({
|
|
14
|
+
contractId: this.accountId,
|
|
15
|
+
method: 'mt_balance_of',
|
|
16
|
+
args: {
|
|
17
|
+
account_id: account.accountId,
|
|
18
|
+
token_id: tokenId,
|
|
19
|
+
},
|
|
16
20
|
});
|
|
17
21
|
return BigInt(balance);
|
|
18
22
|
}
|
|
@@ -24,9 +28,13 @@ export class MultiTokenContract {
|
|
|
24
28
|
* @returns The balances in the smallest unit as bigint[] matching the order of tokenIds
|
|
25
29
|
*/
|
|
26
30
|
async getBatchedBalance(account, tokenIds) {
|
|
27
|
-
const balances = await account.provider.callFunction(
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
const balances = await account.provider.callFunction({
|
|
32
|
+
contractId: this.accountId,
|
|
33
|
+
method: 'mt_batch_balance_of',
|
|
34
|
+
args: {
|
|
35
|
+
account_id: account.accountId,
|
|
36
|
+
token_ids: tokenIds,
|
|
37
|
+
},
|
|
30
38
|
});
|
|
31
39
|
return balances.map((b) => BigInt(b));
|
|
32
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Account } from '../../accounts/account.js';
|
|
2
2
|
interface ContractMetadata {
|
|
3
3
|
spec?: string;
|
|
4
4
|
name: string;
|
|
@@ -27,7 +27,7 @@ export declare class NFTContract {
|
|
|
27
27
|
readonly accountId: string;
|
|
28
28
|
constructor(accountId: string, metadata: ContractMetadata);
|
|
29
29
|
transfer({ from, receiverId, tokenId }: {
|
|
30
|
-
from:
|
|
30
|
+
from: Account;
|
|
31
31
|
receiverId: string;
|
|
32
32
|
tokenId: string;
|
|
33
33
|
}): Promise<any>;
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
package/package.json
CHANGED
package/lib/types/accounts.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
interface ProviderLike {
|
|
2
|
-
callFunction: (contractId: any, methodName: any, args: any, blockQuery?: any) => Promise<any>;
|
|
3
|
-
}
|
|
4
|
-
export interface AccountLike {
|
|
5
|
-
accountId: string;
|
|
6
|
-
provider: ProviderLike;
|
|
7
|
-
getState(): Promise<any>;
|
|
8
|
-
signAndSendTransaction({ receiverId, actions }: {
|
|
9
|
-
receiverId: any;
|
|
10
|
-
actions: any;
|
|
11
|
-
}): Promise<any>;
|
|
12
|
-
callFunction({ contractId, methodName, args, gas, deposit }: {
|
|
13
|
-
contractId: any;
|
|
14
|
-
methodName: any;
|
|
15
|
-
args: any;
|
|
16
|
-
gas: any;
|
|
17
|
-
deposit: any;
|
|
18
|
-
}): Promise<any>;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/lib/types/accounts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|