# node.js 应用说明
# 准备
- 进入 playground 目录
$ cd playground
- (可选)生成一个默认配置文件 package.json
$ npm init -y
- 安装@swtc/lib 库
$ npm install @swtc/lib
# 运行方式
- 交互式运行
$ node
> var Wallet = require('@swtc/lib').Wallet
undefined
> Wallet.generate()
{ secret: 'snJT6UyLWWSpHd7BurPZnXjjvQgYE',
address: 'jw6yC7peFmc9rKWPw5m7fiJE49GQDv5G2m' }
- 脚本文件运行
$ echo -e "const Wallet = require('@swtc/wallet').Wallet\nvar wallet = new Wallet('snJT6UyLWWSpHd7BurPZnXjjvQgYE')\nconsole.log(wallet)" > file.js
$ cat file.js
const Wallet = require('@swtc/wallet').Wallet
var wallet = new Wallet('snJT6UyLWWSpHd7BurPZnXjjvQgYE')
console.log(wallet)
$ node file.js
Wallet {
_keypairs:
{ privateKey:
'00E4196E425F79EC606D49AAC37AB46EF3A4DAC1748451099AA5906751F31C8238',
publicKey:
'02E0C89CE4D8A889153082E91C347B3F5BDA1D12FD26039DB402A6AE659B7E41FB' },
_secret: 'snJT6UyLWWSpHd7BurPZnXjjvQgYE' }
- 半交互式
$ echo -e "const Wallet = require('@swtc/wallet').Wallet\nvar wallet = Wallet.fromSecret('snJT6UyLWWSpHd7BurPZnXjjvQgYE')\n" > file2.js
$ cat file2.js
const Wallet = require('@swtc/wallet').Wallet
var wallet = Wallet.fromSecret('snJT6UyLWWSpHd7BurPZnXjjvQgYE')
$ node
> .load file2.js
const Wallet = require('@swtc/wallet').Wallet
var wallet = Wallet.fromSecret('snJT6UyLWWSpHd7BurPZnXjjvQgYE')
undefined
> console.log(wallet)
{ secret: 'snJT6UyLWWSpHd7BurPZnXjjvQgYE',
address: 'jw6yC7peFmc9rKWPw5m7fiJE49GQDv5G2m' }
undefined
>