npm package: @fingo/asimov-wallet
Description: Asimov Wallet Lib for nodejs
Author: airbc
Latest version: 0.2.16

# AsimovWallet

Asimov Wallet Lib for nodejs

## Install

```bash
npm i @fingo/asimov-wallet
# or
yarn add @fingo/asimov-wallet
```

## Usage

Basic Usage

```javascript
import {AsimovWallet} from 'asimov-wallet'

let wallet = new AsimovWallet({
    name: 'test',
    rpc:'https://rpc-master.mistabit.com',
    mnemonic:'cannon club beach denial swear fantasy donate bag fiscal arrive hole reopen',
    // storage: 'localforage',
})

await wallet.account.createAccount()
let address = wallet.address
let pk = wallet.pk
let mnemonic = wallet.config.mnemonic

let balance = await wallet.account.balance()

let res = await wallet.commonTX.transfer('0x666234b6348c10fed282b95c1f1768aa3113eb96b2',1,AsimovConst.DEFAULT_ASSET_ID)
let res = await wallet.commonTX.detail('22e023b162caff9c9d4e071cbb8f730290856f4a77b91f172bb48ab4fc9b52b9')

```

Create Readonly Wallet

```javascript
let wallet = new AsimovWallet({
    name: 'test',
    rpc:'https://rpc-master.mistabit.com',
    address:'0x66381fed979566a0656a3b422706072915a452ba6b'
})


```

Transaction Hex Data

```javascript

let hexTX = await wallet.commonTX.generateHexTX('0x666234b6348c10fed282b95c1f1768aa3113eb96b2',0.1,
AsimovConst.DEFAULT_ASSET_ID,'','',
AsimovConst.DEFAULT_GAS_LIMIT,
AsimovConst.DEFAULT_FEE_AMOUNT,
AsimovConst.DEFAULT_ASSET_ID)

let hexTX = await wallet.commonTX.generateSignedHexTX('0x666234b6348c10fed282b95c1f1768aa3113eb96b2',0.1,
AsimovConst.DEFAULT_ASSET_ID,'','',
AsimovConst.DEFAULT_GAS_LIMIT,
AsimovConst.DEFAULT_FEE_AMOUNT,
AsimovConst.DEFAULT_ASSET_ID)

let tx = Transaction.fromHex(hexTX)

let singedHexTX = await wallet.commonTX.signHexTX(hex)

```

Contract Call Hex Data

```javascript
let tx = await wallet.contractCall.generateTX(
    '0x6383177655bca94f802191a19282f39e117b8edb2f',
    'UpdateAdmin(address)',
    ["0x66381fed979566a0656a3b422706072915a452ba6b"],
    AsimovConst.DEFAULT_GAS_LIMIT,0,
    AsimovConst.DEFAULT_ASSET_ID,
    AsimovConst.DEFAULT_FEE_AMOUNT,
    AsimovConst.DEFAULT_ASSET_ID,
    AsimovConst.CONTRACT_TYPE.CALL)
let hex1 = tx.toUnsignHex()
tx = await wallet.commonTX.signTX(tx)
let hex2 = tx.toHex()
```

Generate new mnemonic

```javascript
import {Mnemonic} from 'asimov-wallet'
let m = Mnemonic.generate()
```

Call Contract

```javascript
// asi call -c 0x638374231575328e380610fbb12020c29e11afcd01 -m 'balanceOf' -a '["0x66381fed979566a0656a3b422706072915a452ba6b"]'
let res = await wallet.contractCall.callReadOnly(
            '0x638374231575328e380610fbb12020c29e11afcd01',
            'balanceOf',
            ["0x66381fed979566a0656a3b422706072915a452ba6b"])

// or

let res = await wallet.contractCall.callReadOnly(
            '0x638374231575328e380610fbb12020c29e11afcd01',
            'balanceOf(address)',
            ["0x66381fed979566a0656a3b422706072915a452ba6b"])

// asi call -c 0x6383177655bca94f802191a19282f39e117b8edb2f -m 'UpdateAdmin(address)' -a '["0x66381fed979566a0656a3b422706072915a452ba6b"]'
let res = await wallet.contractCall.call(
        '0x6383177655bca94f802191a19282f39e117b8edb2f',
        'UpdateAdmin(address)',
        ["0x66381fed979566a0656a3b422706072915a452ba6b"],
        AsimovConst.DEFAULT_GAS_LIMIT,0,
        AsimovConst.DEFAULT_ASSET_ID,
        AsimovConst.DEFAULT_FEE_AMOUNT,
        AsimovConst.DEFAULT_ASSET_ID,
        AsimovConst.CONTRACT_TYPE.CALL)
```

## MutliSig Wallet

```javascript
// wallet1 create 2/3
let createProposal1 = await wallet.account.createMultiSigAccount('wallet name','payer1 name',2,3)
// wallet2
let createProposal2 = await wallet.account.joinMultiSigAccount(createProposal1, 'payer2 name')
// wallet3
let createProposal3 = await wallet.account.joinMultiSigAccount(createProposal2, 'payer3 name')

// wallet1,2,3
await wallet.account.importMultiSigAccount(createProposal3)

// wallet1 1/3
let txProposal1 = await wallet.account.createMultiSigProposal('wallet name',params)
// wallet2 2/3
let txProposal2 = await wallet.account.signMultiSigProposal('wallet name',txProposal1)
// whatever wallet broadcast it
let res = await wallet.commonTX.sendRawTX(txProposal2.toHex())
```

## Test

```bash
npm run test
# or
yarn test
```

## TBD

* [ ] Vote Contract
* [x] Multi-Addresses Transfer
* [ ] Memory-Pool TX Checking
* [ ] Local Cache of used UTXOs