Asimov Wallet Lib for nodejs
npm i asimov-wallet
# or
yarn add asimov-wallet
Basic Usage
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
let wallet = new AsimovWallet({
name: 'test',
rpc:'https://rpc-master.mistabit.com',
address:'0x66381fed979566a0656a3b422706072915a452ba6b'
})
Transaction Hex Data
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
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
import {Mnemonic} from 'asimov-wallet'
let m = Mnemonic.generate()
Call Contract
// 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)
npm i mocha -g
npm run test
- [ ] Vote Contract
- [x] MultiSig Wallet
// 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())
VER:1.0.126
// Address.ts
// ...
constructor(public data, public type: string = Address.PayToPublicKeyHash, public network: Network | string = 'testnet')
// ...
static _transformBuffer(buffer, network, type) {
// ...
// FIXME: type always has default value
if (!bufferVersion.type || (type && type !== bufferVersion.type)) {
throw new TypeError('Address has mismatched type.');
}
// change to
if (!bufferVersion.type) {
throw new TypeError('Address has mismatched type.');
}
// ...
}
TypeError: Cannot read property 'makeFullTupleTypeDefinition' of undefined
// node_modules/@asimovdev/asimovjs/lib/utils/TxHelper.js
// makeFullTupleTypeDefinition
this.extractSize(typeDef.type)
// to
extractSize(typeDef.type)
// encodeParams
this.makeFullTupleTypeDefinition(funABI.inputs[i]) : type)
// to
makeFullTupleTypeDefinition(funABI.inputs[i]) : type)