-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathdeploy-contract.ts
39 lines (34 loc) · 1.52 KB
/
deploy-contract.ts
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
import {
deployContract,
getSignerFromKeystore,
getTestnetRpcProvider,
} from '@near-js/client';
import { UnencryptedFileSystemKeyStore } from '@near-js/keystores-node';
import chalk from 'chalk';
import { join } from 'node:path';
import { homedir } from 'node:os';
import * as fs from 'node:fs/promises';
const WASM_PATH = join(__dirname, '/wasm-files/status_message.wasm');
export default async function deployContractCookbook(accountId: string, wasmPath: string = WASM_PATH) {
if (!accountId) {
console.log(chalk`{red pnpm deployContract -- ACCOUNT_ID [WASM_PATH]}`);
return;
}
// initialize testnet RPC provider
const rpcProvider = getTestnetRpcProvider();
// initialize the transaction signer using a pre-existing key for `accountId`
const signer = getSignerFromKeystore(accountId, 'testnet', new UnencryptedFileSystemKeyStore(join(homedir(), '.near-credentials')));
await deployContract({
account: accountId,
code: await fs.readFile(wasmPath),
deps: {
rpcProvider,
signer,
},
});
console.log(chalk`{white ------------------------------------------------------------------------ }`);
console.log(chalk`{bold.green RESULTS} {white Deployed contract}` );
console.log(chalk`{white ------------------------------------------------------------------------ }`);
console.log(chalk`{bold.white Contract Deployed} {white |} {bold.yellow WASM at ${wasmPath} deployed to ${accountId}}`);
console.log(chalk`{white ------------------------------------------------------------------------ }`);
}