This repository was archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathnear-cli.js
More file actions
205 lines (193 loc) · 5.71 KB
/
near-cli.js
File metadata and controls
205 lines (193 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const yargs = require('yargs');
const main = require('../');
const exitOnError = require('../utils/exit-on-error');
const chalk = require('chalk');
// For account:
const login = {
command: 'login',
desc: 'logging in through NEAR protocol wallet',
builder: (yargs) => yargs
.option('walletUrl', {
desc: 'URL of wallet to use',
type: 'string',
required: false
}),
handler: exitOnError(main.login)
};
const viewAccount = {
command: 'state <accountId>',
desc: 'view account state',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to view',
type: 'string',
required: true
}),
handler: exitOnError(main.viewAccount)
};
const deleteAccount = {
command: 'delete <accountId> <beneficiaryId>',
desc: 'delete an account and transfer funds to beneficiary account.',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to view',
type: 'string',
required: true
})
.option('beneficiaryId', {
desc: 'Account to transfer funds to',
type: 'string',
required: true
}),
handler: exitOnError(main.deleteAccount)
};
const keys = {
command: 'keys <accountId>',
desc: 'view account public keys',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to view',
type: 'string',
required: true
}),
handler: exitOnError(main.keys)
};
const sendMoney = {
command: 'send <sender> <receiver> <amount>',
desc: 'send tokens to given receiver',
builder: (yargs) => yargs
.option('amount', {
desc: 'Amount of NEAR tokens to send',
type: 'string',
}),
handler: exitOnError(main.sendMoney)
};
const stake = {
command: 'stake [accountId] [stakingKey] [amount]',
desc: 'create staking transaction',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to stake on',
type: 'string',
required: true,
})
.option('stakingKey', {
desc: 'Public key to stake with (base58 encoded)',
type: 'string',
required: true,
})
.option('amount', {
desc: 'Amount to stake',
type: 'string',
required: true,
}),
handler: exitOnError(main.stake)
};
// For contract:
const deploy = {
command: 'deploy',
desc: 'deploy your smart contract',
builder: (yargs) => yargs
.option('wasmFile', {
desc: 'Path to wasm file to deploy',
type: 'string',
default: './out/main.wasm'
})
.alias({
'accountId': ['account_id', 'contractName', 'contract_name'],
}),
handler: exitOnError(main.deploy)
};
const callViewFunction = {
command: 'view <contractName> <methodName> [args]',
desc: 'make smart contract call which can view state',
builder: (yargs) => yargs,
handler: exitOnError(main.callViewFunction)
};
const { spawn } = require('child_process');
const build = {
command: 'build',
desc: 'build your smart contract',
handler: () => {
const gulp = spawn('gulp', [], {shell: process.platform == 'win32'});
gulp.stdout.on('data', function (data) {
console.log(data.toString());
});
gulp.stderr.on('data', function (data) {
console.log(data.toString());
});
gulp.on('exit', function (code) {
process.exit(code);
});
}
};
const clean = {
command: 'clean',
desc: 'clean the build environment',
builder: (yargs) => yargs
.option('outDir', {
desc: 'build directory',
type: 'string',
default: './out'
}),
handler: exitOnError(main.clean)
};
let config = require('../get-config')();
yargs // eslint-disable-line
.middleware(require('../utils/check-version'))
.scriptName('near')
.option('nodeUrl', {
desc: 'NEAR node URL',
type: 'string',
default: 'http://localhost:3030'
})
.option('networkId', {
desc: 'NEAR network ID, allows using different keys based on network',
type: 'string',
default: 'default'
})
.option('helperUrl', {
desc: 'NEAR contract helper URL',
type: 'string',
})
.option('keyPath', {
desc: 'Path to master account key',
type: 'string',
})
.option('accountId', {
desc: 'Unique identifier for the account',
type: 'string',
})
.middleware(require('../middleware/print-options'))
.middleware(require('../middleware/key-store'))
.command(require('../commands/create-account'))
.command(viewAccount)
.command(deleteAccount)
.command(keys)
.command(require('../commands/tx-status'))
.command(build)
.command(deploy)
.command(require('../commands/dev-deploy'))
.command(require('../commands/call'))
.command(callViewFunction)
.command(sendMoney)
.command(clean)
.command(stake)
.command(login)
.command(require('../commands/repl'))
.command(require('../commands/generate-key'))
.config(config)
.alias({
'accountId': ['account_id'],
'nodeUrl': 'node_url',
'networkId': ['network_id'],
'wasmFile': 'wasm_file',
'projectDir': 'project_dir',
'outDir': 'out_dir'
})
.showHelpOnFail(true)
.demandCommand(1, chalk`Pass {bold --help} to see all available commands and options.`)
.usage(chalk`Usage: {bold $0 <command> [options]}`)
.epilogue(chalk`Check out our epic whiteboard series: {bold http://near.ai/wbs}`)
.wrap(null)
.argv;