{"_id":"@bytesalt/qtumjs-wallet","_rev":"1-05d9a6b3af124480cfa6d068b1d1ac2a","name":"@bytesalt/qtumjs-wallet","dist-tags":{"latest":"0.2.1"},"versions":{"0.2.1":{"name":"@bytesalt/qtumjs-wallet","version":"0.2.1","description":"A toolkit for building qtum light wallets","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"start-services":"./scripts/start-services.sh","build":"tsc -w","clean":"docker-compose stop && docker-compose rm -f && rm -rf ./data && rm -rf lib","test":"tsc && mocha lib/**/*.test.js","test-watch":"tsc -w & mocha -w lib/**/*.test.js"},"keywords":[],"author":{"name":"bytesalt"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/bytesalt/qtumjs-wallet.git"},"devDependencies":{"@types/bitcoinjs-lib":"^3.3.1","@types/chai":"^4.1.2","@types/mocha":"^2.2.48","@types/node":"^8.9.1","chai":"^4.1.2","mocha":"^5.2.0","tslint":"^6.1.3","typescript":"^3.6.5"},"dependencies":{"@types/bip38":"^2.0.0","@types/secp256k1":"^3.5.0","axios":"^0.20.0","bignumber.js":"4.1.0","bip38":"^2.0.2","bip39":"^2.5.0","buffer":"^5.1.0","coinselect":"^3.1.11","elliptic":"^6.5.3","hash.js":"^1.1.5","@bytesalt/qtumd-rpc":"^0.0.2","@bytesalt/qtumjs-lib":"^0.0.6","safe-buffer":"^5.1.1","scryptsy":"^2.0.0","secp256k1":"^4.0.2","varuint-bitcoin":"^1.1.0"},"bugs":{"url":"https://github.com/bytesalt/qtumjs-wallet/issues"},"homepage":"https://github.com/bytesalt/qtumjs-wallet#readme","directories":{"lib":"lib"},"gitHead":"517a0912938246bdeaf35efb8cdb5a82f5486b73","_id":"@bytesalt/qtumjs-wallet@0.2.1","_nodeVersion":"12.18.4","_npmVersion":"6.14.6","dist":{"integrity":"sha512-CzBIw5p1j6biQryBOG/WopjosmswBdG6TE+GzYqu/Zdzs9Zjut/9/urZXhZ4CaFD5cHWlR0dmVslo5KBgEN2Jw==","shasum":"2720589a5e2eca09b83cfdee91aebbcae5716c7a","tarball":"https://registry.npmjs.org/@bytesalt/qtumjs-wallet/-/qtumjs-wallet-0.2.1.tgz","fileCount":67,"unpackedSize":140276,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfcjVXCRA9TVsSAnZWagAAoIkP/3p98srR9EMUcdUVZe7O\n8D7QgE8PKBg03VKPLdcZDhzlK1dehzoswmRdHxIP45U+poNp5Nki5W3BJy7b\nGEUvm4wQWTQnP3ax0NFlLO9GoHCJP8X9iCURfrIyBkdABLOcjkhdQNp+Yl02\n6bxtYjcVzbx+gOZq21Cr2ws06fG9k43h6aE98AmGt14ePkzes7RdM3JlSNSi\n1PlDvwAtZwmugATc+VI35PnAve3d5WFPwnaO+Xbiow+sS5o0okAOsMYBPoma\n9G5oYSCn/7lObzeeRTlcmu7WhbeP0toF89kxuJd88G3W68SVXOG+kL8Zibyu\nuJuFofRtz+7hbArjAZNoD7+a4r1cbeWWGYKAbQzFcOrrvhZzAZ8OtoMhvaUJ\nqKZ86GWRPT/Pdgg+kDtt1FNeq8UjiEo7E6ZGjLjcuYnW3N02V0Q2H5QgvQn7\nnCI7Di1vwcqK9h68VSs2hd60I/FMueA2+mCGd3KYBZYiImPzo2XBZ68zpjIA\nY6h5f71fYnHnkJVtTDC+lJnhTbrRZcAt7X9j6Sw0llL1uGhIgof3kRzoiPG1\nWISTZmAMY9FSprAjYT6uJUXYQO5hMO6/eVr2zOLGU4I8YetDflQ61MZ66Sts\nDmKOncEufzynT3ze7pSeoQwd3rY7NMYswAP5M9PK79pdJcX/RDKlqEb8y4RL\nH3/1\r\n=QEQk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDdcwZCyKggtcbnkSCmnYU0zdMirccIxPFo9rpPtE10AQIhAI4fkYQGDDsz+CHS3PGoXkFetVQ0z6eEJS0PUhB+4m2u"}]},"maintainers":[{"name":"bytesalt","email":"leandro@usocoins.com.br"}],"_npmUser":{"name":"bytesalt","email":"leandro@usocoins.com.br"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/qtumjs-wallet_0.2.1_1601320279171_0.09224862549632928"},"_hasShrinkwrap":false}},"time":{"created":"2020-09-28T19:11:19.132Z","0.2.1":"2020-09-28T19:11:19.329Z","modified":"2022-04-04T21:22:19.165Z"},"maintainers":[{"name":"bytesalt","email":"leandro@usocoins.com.br"}],"description":"A toolkit for building qtum light wallets","homepage":"https://github.com/bytesalt/qtumjs-wallet#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/bytesalt/qtumjs-wallet.git"},"author":{"name":"bytesalt"},"bugs":{"url":"https://github.com/bytesalt/qtumjs-wallet/issues"},"license":"ISC","readme":"# QtumJS Wallet\n\nThis is a client-side wallet library that can generate private keys from a mnemonic, or import private keys from other QTUM wallets.\n\nIt can sign transactions locally, and submit the raw transaction data to a remote qtum node. The blockchain data is provided by the Insight API (which powers https://explorer.qtum.org/), rather than the raw qtumd RPC calls.\n\nThis library makes it possible to run DApp without the users having to run a full qtumd node.\n\n> This library is extracted from the official [QTUM web wallet](https://github.com/qtumproject/qtum-web-wallet).\n\n## Install\n\n```\nyarn add qtumjs-wallet\n```\n\n## Running Tests\n\nThe qtumjs-wallet depends on a number of external services. To run the unit tests, you'll need to start the services using [docker-compose](https://docs.docker.com/compose/install/).\n\n```\nnpm run start-services\n```\n\nThen run the tests:\n\n```\nnpm run test\n```\n\nOr, to rebuild and rerun tests automatically:\n\n```\nnpm run test-watch\n```\n\nIf you did not terminate the testing docker services properly, run the clean task first before restart:\n\n```\nnpm run clean\n```\n\n## Implementation Notes\n\nThere are some differences from the original web wallet repo.\n\n- Removed VUE specific code.\n- Removed reactive data setters that are intended to trigger view updates, to make this a plain-old JavaScript module.\n- Each wallet instance is instantiated with a network explicitly. This allows simultaneous use of different networks.\n- TypeScript for type hinting.\n- Uses satoshi (1e8) as internal units\n  - Can represent up to ~90 million QTUM accurately.\n- Uses [coinselect](https://github.com/bitcoinjs/coinselect) to select utxos.\n  - Taking into account the size of a transaction, and multiplies that by fee rate per byte.\n  - Uses blackjack algorithm, and fallbacks to simple accumulative.\n- Set tx relay fee automatically from fee rate reported by the network.\n- send-to-contract transaction can transfer value to the contract\n\n# API\n\n- [Networks](#networks)\n  - [fromWIF](#fromwif)\n  - [fromMnemonic](#frommnemonic)\n  - [fromEncryptedPrivateKey](#fromencryptedprivatekey)\n- [Wallet](#wallet)\n  - [async wallet.getInfo](#async-walletgetinfo)\n  - [async wallet.send](#async-walletsend)\n  - [async wallet.sendEstimateMaxValue](#async-walletsendestimatemaxvalue)\n  - [async wallet.generateTx](#async-walletgeneratetx)\n  - [async wallet.contractSend](#async-walletcontractsend)\n  - [async wallet.contractSendEstimateMaxValue](#async-walletcontractsendestimatemaxvalue)\n  - [async wallet.generateContractSendTx](#async-walletgeneratecontractsendtx)\n  - [async wallet.contractCall](#async-walletcontractcall)\n  - [async getTransactions](#async-gettransactions)\n  - [toEncryptedPrivateKey](#toencryptedprivatekey)\n  - [deriveChildWallet](#derivechildwallet)\n\n# Examples\n\n## Create Mnemonic+Password Wallet\n\n```js\nimport { networks, generateMnemonic } from \"qtumjs-wallet\";\n\nasync function main() {\n  const network = networks.testnet;\n  const mnemonic = generateMnemonic();\n  const password = \"covfefe\";\n\n  const wallet = network.fromMnemonic(mnemonic, password);\n\n  console.log(\"mnemonic:\", mnemonic);\n  console.log(\"public address:\", wallet.address);\n  console.log(\"private key (WIF):\", wallet.toWIF());\n}\n\nmain().catch(err => console.log(err));\n```\n\nExample Output:\n\n```\nmnemonic: hold struggle ready lonely august napkin enforce retire pipe where avoid drip\npublic address: qLUHmrFGexxpyHwQphLpE1czZNFE5m1xmV\nprivate key (WIF): cNQKccYYQyGX9G9Qxq2DJev9jHygbZpb2UG7EvUapbtDx5XhkhYE\n```\n\n## Send Fund\n\nThis example restores a wallet from a private key (in [WIF](https://en.bitcoin.it/wiki/Wallet_import_format) format), then sending value to another address.\n\nThe transaction is signed locally, and the transaction submitted to a remote API.\n\nThe currency unit used is `satoshi`. To convert qtum to satoshi you should multiply the amount you want with `1e8`.\n\n```js\nimport { networks } from \"qtumjs-wallet\";\n\nasync function main() {\n  // Use the test network. Or `networks.mainnet`\n  const network = networks.testnet;\n\n  const wif = \"cU4ficvRNvR7jnbtczCWo5s9rB9Tdg1U4LkArVpGU6cKnDq7LFoP\";\n  const wallet = network.fromWIF(wif);\n\n  console.log(wallet.address);\n\n  const toAddr = \"qS3ThpDn4HRH9we2hZUdF3F3uR7TTvpZ9v\";\n  // Sending 0.1 qtum\n  const sendtx = await wallet.send(toAddr, 0.01 * 1e8, { feeRate: 500 });\n  console.log(\"sendtx\", sendtx);\n}\n\nmain().catch(err => console.log(err));\n```\n\n## Send To Contract\n\nLet's burn some money using the `Burn` contract:\n\n```solidity\npragma solidity ^0.4.18;\n\ncontract Burn {\n  uint256 public totalburned;\n  event DidBurn(address burnerAddress, uint256 burnedAmount);\n\n  function burnbabyburn() public payable {\n    totalburned = msg.value;\n    DidBurn(msg.sender, msg.value);\n  }\n}\n```\n\nThe ABI encoding for the `burnbabyburn()` invokation is `e179b912`. We'll burn 0.05 qtum, expressed in unit of satoshi.\n\n```ts\nimport { networks } from \"qtumjs-wallet\";\n\nasync function main() {\n  const network = networks.testnet;\n\n  const privateKey = \"cU4ficvRNvR7jnbtczCWo5s9rB9Tdg1U4LkArVpGU6cKnDq7LFoP\";\n\n  const wallet = network.fromWIF(privateKey);\n\n  const contractAddress = \"b10071ee33512ce8a0c06ecbc14a5f585a27a3e2\";\n  const encodedData = \"e179b912\"; // burnbabyburn()\n\n  const tx = await wallet.contractSend(contractAddress, encodedData, {\n    amount: 0.05 * 1e8 // 0.05 qtum in satoshi\n  });\n\n  console.log(tx);\n}\n\nmain().catch(err => console.log(err));\n```\n\n# Networks\n\nTwo networks are predefined:\n\n```js\nimport { networks } from \"qtumjs-wallet\";\n\n// Main Network\nnetworks.mainnet;\n\n// Test Network\nnetworks.testnet;\n```\n\n## fromPrivateKey\n\nAlias for `fromWIF`.\n\n## fromWIF\n\n`fromWIF` constructs a wallet from private key (in [WIF](https://en.bitcoin.it/wiki/Wallet_import_format) format).\n\nSuppose you want to import the public address `qg3HYD8c4bAVLeEzA9t3Ken3Y3Mni1HZSS`. Use `qtum-cli` to dump the private key from wallet:\n\n```\nqcli dumpprivkey qg3HYD8c4bAVLeEzA9t3Ken3Y3Mni1HZSS\n\ncVHzWuEKUxoRKba9ySZFqUKZ9G5W8NkzthRcPaB65amUJs95RM3d\n```\n\n```js\nconst network = networks.testnet;\n\nconst privateKey = \"cVEwiJ5NMTdnkW4ZW2ykUopawtLPXQWtPDmvpTh5jmXYMtg8itAz\";\n\nconst wallet = network.fromWIF(privateKey);\nconsole.log(\"public address:\", wallet.address);\n```\n\nOutput:\n\n```\npublic address: qWAnfBnRNhZBqtgSdgHjSfS2D5Jawmafra\n```\n\n## fromMnemonic\n\n`fromMnemonic` constructs a wallet from mnemonic. User can optionally specify a `password` to add to the mnemonic entropy.\n\n```ts\nconst network = networks.testnet;\nconst mnemonic =\n  \"hold struggle ready lonely august napkin enforce retire pipe where avoid drip\";\nconst password = \"covfefe\";\n\nconst wallet = network.fromMnemonic(mnemonic, password);\n\nconsole.log(\"public address:\", wallet.address);\nconsole.log(\"private key (WIF):\", wallet.toWIF());\n```\n\nExample Output:\n\n```\npublic address: qLUHmrFGexxpyHwQphLpE1czZNFE5m1xmV\nprivate key (WIF): cNQKccYYQyGX9G9Qxq2DJev9jHygbZpb2UG7EvUapbtDx5XhkhYE\n```\n\n# Wallet\n\nWallet manages blockchain access for an address. It is able to create and sign transactions locally for sending a payment or interacting with a smart contract.\n\nYou would typically construct a Wallet instance using the factory methods provided by `Network`.\n\n## async wallet.getInfo\n\nGet basic information about the wallet address.\n\nExample:\n\n```ts\nconst info = await wallet.getInfo();\nconsole.log(info);\n```\n\nOutput:\n\n```\n{ addrStr: 'qbkJZTKQfcout2joWVmnvUrJUDTg93bhdv',\n  balance: 128.47960699,\n  balanceSat: 12847960699,\n  totalReceived: 599.92142295,\n  totalReceivedSat: 59992142295,\n  totalSent: 471.44181596,\n  totalSentSat: 47144181596,\n  unconfirmedBalance: 0,\n  unconfirmedBalanceSat: 0,\n  unconfirmedTxApperances: 0,\n  txApperances: 21,\n  transactions:\n   [ 'd12ff9cfd76836d8eb5a39bc40f1dc5e6e2032bfa132f66cca638a7e76f2b6e7',\n     '44fa64f34361cf5460ca116ea396098eb0d20dd43839375c07d69a282d4e29b6',\n     'ca86c477bc595f08f158eed0d4307ee6e1e674a2c14f808b013b38cb1e929aa0',\n     'fbf41aaca56dd013934471b4630f8ca52a6216cf791701a07f3e5c0ba16902d5',\n     'af8fff4a74ff9217d629c17aa84412e8810888983cbc4f6b764740e68b51e5d0',\n     'e9172194ef9493a2dd8dddd02aa58a1c13dbfb09a7e04cb97558d951e4b93a88',\n     '3e167a2534d5d18b71ba56bbba8bfdb317711b3f2ef30f10d34941ddc9aa4861',\n     'bd15b9d9cf4e94915e246a7d78de14cb0a6acec12624902b45717997ef71854e',\n     '0c99d68c261dd713819c068bd0213bc048bd4928b3d86d71503bb3348d7f42f5',\n     'd5b823bb524862855181d231e716ff86fa301f701fd4c23b68168debe334da2e',\n     '7660e89eb45b536b9c7527edafc0884fc2941c0f050625780d3e100c8aeb28f4',\n     'eddbbac9bb7dae1cf4093d893133eb52c483b13ea66f6354c63302f9127ec1bd',\n     '6f99149d78ad720591b4cca643fe2599a0a07076f8f3e80b5962cba326772e83',\n     '0ef2548cceaaa41b7c0127f6e943d103f2fcc236d05e59593e05381f7a8474a0',\n     '851753842d80e8dea92de643e0f3784cf7cbdbb02ae879593cbeac2c78560bac',\n     '729c839d63f7426a1f4ada7eb5a35b556556665a4b42e102694674551752bb03',\n     'ee50d8422dce064d40eb021f4829f5b871e8d2927d93ea136dc0df01b1a72e08',\n     'caf8b48b9d38c3a27de3d24c5a738f63ec37619d419cfcd061bc991d8369bda3',\n     '3b59444033d61457fe229a866dc9cb4a60a4b070ea3a73cacba27516fd30cee8',\n     '5e9ca1c946deaf5458d2b6236145b225eee61ec6991b7df8ee96573b53d82584',\n     'cfbadf76884ca661816f25487f6493826579afe257517ebd7d1fc2b0020eb289' ] }\n```\n\n## async wallet.send\n\nSend payment to a receiving address. The transaction is signed locally using the\nwallet's private key, and the raw transaction submitted to a remote API (without\nrevealing the wallet's secret).\n\nMethod signature:\n\n```ts\n/**\n * @param to The receiving address\n * @param amount The amount to transfer (in satoshi)\n * @return The raw transaction as hexadecimal string\n *\n */\npublic async send(\n  to: string,\n  amount: number,\n  opts: ISendTxOptions = {},\n): Promise<Insight.ISendRawTxResult>\n```\n\nExample:\n\n```ts\nconst toAddress = \"qZaTYNEimGLuqnBDpP3KvBKsFs3DbCuwnr\";\nconst amount = 0.15 * 1e8; // 0.15 QTUM\n\nconst tx = await wallet.send(toAddress, amount);\nconsole.log(tx);\n```\n\nOutput:\n\n```\n{ txid: '40fec162e0d4e1377b5e6744eeba562408e22f60399be41e7ba24e1af37f773c' }\n```\n\n#### async wallet.send options\n\n```ts\nexport interface ISendTxOptions {\n  /**\n   * Fee rate to pay for the raw transaction data (satoshi per byte). The\n   * default value is the query result of current network's fee rate.\n   */\n  feeRate?: number;\n}\n```\n\nSetting tx fee rate manually:\n\n```ts\nconst tx = await wallet.send(toAddress, amount, {\n  // rate is 400 satoshi per byte, or  ~0.004 qtum/KB, as is typical.\n  feeRate: 400\n});\n```\n\n## async wallet.sendEstimateMaxValue\n\nEstimate the maximum value that could be sent from this wallet address.\n\n```ts\nconst maxSend = await wallet.sendEstimateMaxValue(toAddress);\n```\n\n## async wallet.generateTx\n\nGenerate and sign a payment transaction.\n\nMethod signature:\n\n```ts\n/**\n * @param to The receiving address\n * @param amount The amount to transfer (in satoshi)\n * @param opts\n *\n * @returns The raw transaction as hexadecimal string\n */\npublic async generateTx(\n  to: string,\n  amount: number,\n  opts: ISendTxOptions = {},\n): Promise<string>\n```\n\nExample:\n\n```ts\nconst toAddress = \"qZaTYNEimGLuqnBDpP3KvBKsFs3DbCuwnr\";\nconst amount = 0.15 * 1e8;\n\nconst rawtx = await wallet.generateTx(toAddress, amount);\nconsole.log(rawtx);\n```\n\nExample output, the raw transaction as hexadecimal string:\n\n```\n0100000001a09a921ecb383b018b804fc1a274e6e1e67e30d4d0ee58f1085f59bc77c486ca010000006a47304402202fa6106aca6c682ab89b02ad62614462d1ec5e95cb8b4810ce793ad52a4002590220531cf380368cb8f92c7dd03ee375423073a14e5b7da6f48127c63cab17fbf2d7012103c12c73abaccf35b40454e7eb0c4b5760ce7a720d0cd2c9fb7f5423168aaeea03ffffffff02c0e1e400000000001976a914afb616c886f0efd9a9a486ccc07a09ab8d7a4bb288ac49b6ffe0010000001976a914c78300c58ab7c73e1767e3d550464d591ab0a12888ac00000000\n```\n\nYou can decode the raw transaction using `qtum-cli`:\n\n```\nqtum-cli decoderawtransaction 0100000001a09a921ecb38...\n\n{\n  // ...\n  \"vout\": [\n    {\n      \"value\": 0.15000000,\n      \"n\": 0,\n      \"scriptPubKey\": {\n        \"asm\": \"OP_DUP OP_HASH160 afb616c886f0efd9a9a486ccc07a09ab8d7a4bb2 OP_EQUALVERIFY OP_CHECKSIG\",\n        \"hex\": \"76a914afb616c886f0efd9a9a486ccc07a09ab8d7a4bb288ac\",\n        \"reqSigs\": 1,\n        \"type\": \"pubkeyhash\",\n        \"addresses\": [\n          \"qZaTYNEimGLuqnBDpP3KvBKsFs3DbCuwnr\"\n        ]\n      }\n    },\n    {\n      \"value\": 80.69822025,\n      \"n\": 1,\n      \"scriptPubKey\": {\n        \"asm\": \"OP_DUP OP_HASH160 c78300c58ab7c73e1767e3d550464d591ab0a128 OP_EQUALVERIFY OP_CHECKSIG\",\n        \"hex\": \"76a914c78300c58ab7c73e1767e3d550464d591ab0a12888ac\",\n        \"reqSigs\": 1,\n        \"type\": \"pubkeyhash\",\n        \"addresses\": [\n          \"qbkJZTKQfcout2joWVmnvUrJUDTg93bhdv\"\n        ]\n      }\n    }\n  ]\n}\n```\n\nThere are two vouts:\n\n1. pubkeyhash 0.15. This is the amount we want to send.\n2. pubkeyhash 80.69822025. This is the amount we going back to the original owner as change.\n\n## async wallet.contractSend\n\nCreate a send-to-contract transaction that invokes a contract's method.\n\n```ts\n/**\n  * @param contractAddress Address of the contract in hexadecimal\n  * @param encodedData The ABI encoded method call, and parameter values.\n  * @param opts\n  */\npublic async contractSend(\n  contractAddress: string,\n  encodedData: string,\n  opts: IContractSendTXOptions = {},\n): Promise<Insight.ISendRawTxResult>\n```\n\nExample:\n\nInvoke the `burn()` method, and transfer 5000000 satoshi to the contract.\n\n- The `burn()` method call ABI encodes to `e179b912`\n- The 5000000 is `msg.value` in contract code.\n\n```ts\nconst contractAddress = \"1620cd3c24b29d424932ec30c5925f8c0a00941c\";\n// ABI encoded data for the send-to-method transaction\nconst encodedData = \"e179b912\";\n\n// Invoke a contract's method, and transferring 0.05 to it.\nconst tx = await wallet.contractSend(contractAddress, encodedData, {\n  amount: 0.05 * 1e8\n});\n\nconsole.log(tx);\n```\n\nOutput:\n\n```\n{ txid: 'd12ff9cfd76836d8eb5a39bc40f1dc5e6e2032bfa132f66cca638a7e76f2b6e7' }\n```\n\n## async wallet.contractSendEstimateMaxValue\n\nEstimate the maximum value that could be sent to a contract, substracting the amount reserved for gas.\n\n```ts\nconst maxContractSend = await wallet.contractSendEstimateMaxValue(\n  contractAddress,\n  callDataHex,\n  {\n    gasLimit: 250000,\n    gasPrice: 40\n  }\n);\n```\n\n## async wallet.generateContractSendTx\n\nGenerate a raw a send-to-contract transaction that invokes a contract's method.\n\nMethod signature:\n\n```ts\n/**\n  * @param contractAddress\n  * @param encodedData\n  * @param opts\n  */\npublic async generateContractSendTx(\n  contractAddress: string,\n  encodedData: string,\n  opts: IContractSendTXOptions = {},\n): Promise<string>\n```\n\nExample:\n\n```ts\nconst contractAddress = \"1620cd3c24b29d424932ec30c5925f8c0a00941c\";\nconst encodedData = \"e179b912\";\n\nconst rawtx = await wallet.generateContractSendTx(\n  contractAddress,\n  encodedData,\n  {\n    amount: 0.01 * 1e8\n  }\n);\n\nconsole.log(rawtx);\n```\n\nExample output:\n\n```\n0100000001e7b6f2767e8a63ca6cf632a1bf32206e5edcf140bc395aebd83668d7cff92fd1010000006b483045022100b86c4cbb2aecab44c951f99c0cbbf6115cf80881b39f33b4efd4d296892c1c15022062db1f681e684616e55303556577c9242102ff7a6815894dfb3090a7928fa13a012103c12c73abaccf35b40454e7eb0c4b5760ce7a720d0cd2c9fb7f5423168aaeea03ffffffff0240420f000000000022540390d003012804e179b912141620cd3c24b29d424932ec30c5925f8c0a00941cc2880256e0010000001976a914c78300c58ab7c73e1767e3d550464d591ab0a12888ac00000000\n```\n\nDecode the raw transaction:\n\n```\nqtum-cli decoderawtransaction 0100000001e7b6f2767e8a6...\n```\n\nDecoded Raw TX:\n\n```ts\n{\n  // ...\n  \"vout\": [\n    {\n      \"value\": 0.01000000,\n      \"n\": 0,\n      \"scriptPubKey\": {\n        \"asm\": \"4 250000 40 314145249 1620cd3c24b29d424932ec30c5925f8c0a00941c OP_CALL\",\n        \"hex\": \"540390d003012804e179b912141620cd3c24b29d424932ec30c5925f8c0a00941cc2\",\n        \"type\": \"call\"\n      }\n    },\n    {\n      \"value\": 80.58700424,\n      \"n\": 1,\n      \"scriptPubKey\": {\n        \"asm\": \"OP_DUP OP_HASH160 c78300c58ab7c73e1767e3d550464d591ab0a128 OP_EQUALVERIFY OP_CHECKSIG\",\n        \"hex\": \"76a914c78300c58ab7c73e1767e3d550464d591ab0a12888ac\",\n        \"reqSigs\": 1,\n        \"type\": \"pubkeyhash\",\n        \"addresses\": [\n          \"qbkJZTKQfcout2joWVmnvUrJUDTg93bhdv\"\n        ]\n      }\n    }\n  ]\n}\n```\n\nThere are two vouts:\n\n1. call 0.11. This is the amount we want to send to the contract.\n2. pubkeyhash 80.58700424. This is the amount we going back to the original owner as change.\n\n## async wallet.contractCall\n\nQuery a contract's method. It returns the result and logs of a simulated execution of the contract's code.\n\nMethod signature:\n\n```ts\n/**\n * @param contractAddress Address of the contract in hexadecimal\n * @param encodedData The ABI encoded method call, and parameter values.\n * @param opts\n */\npublic async contractCall(\n  contractAddress: string,\n  encodedData: string,\n  opts: IContractSendTXOptions = {},\n): Promise<Insight.IContractCall>\n```\n\nExample:\n\n```ts\nconst contractAddress = \"b10071ee33512ce8a0c06ecbc14a5f585a27a3e2\";\nconst encodedData = \"e179b912\";\n\nconst result = await wallet.contractCall(contractAddress, encodedData, {\n  amount: 0.01 * 1e8\n});\n\nconsole.log(JSON.stringify(result, null, 2));\n```\n\nOutput:\n\n```ts\n{\n  \"address\": \"b10071ee33512ce8a0c06ecbc14a5f585a27a3e2\",\n  \"executionResult\": {\n    \"gasUsed\": 27754,\n    \"excepted\": \"None\",\n    \"newAddress\": \"b10071ee33512ce8a0c06ecbc14a5f585a27a3e2\",\n    \"output\": \"\",\n    \"codeDeposit\": 0,\n    \"gasRefunded\": 0,\n    \"depositSize\": 0,\n    \"gasForDeposit\": 0\n  },\n  \"transactionReceipt\": {\n    \"stateRoot\": \"c04b98dbd1a38be8ecfb71e40072c90a1ee9f5961bb80fa6262f8a32979427bb\",\n    \"gasUsed\": 27754,\n    \"bloom\": \"000000000000000000002000400000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000\n00000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\n    \"log\": [\n      {\n        \"address\": \"b10071ee33512ce8a0c06ecbc14a5f585a27a3e2\",\n        \"topics\": [\n          \"9c31339612219a954bda4c790e4b182b6499bdf1464c392cb50e61d8afa1f9f2\"\n        ],\n        \"data\": \"000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000\"\n      }\n    ]\n  }\n}\n```\n\n## getTransactions\n\nGet transactions about the wallet address.\n\nMethod signature:\n\n```ts\n/**\n * get transactions by wallet address\n * @param pageNum page number\n */\npublic async getTransactions(pageNum?: number): Promise<Insight.IRawTransactions>\n```\n\nExample:\n\n```ts\nconst network = networks.testnet;\n\nconst insight = network.insight();\n\nconst info = await insight.getTransactionInfo(\n  \"f20914f3d810010c0a74df60abb3fcf0d3ff2669d944ce187f079ec9faec563e\"\n);\nconsole.log(info);\n```\n\nExample output:\n\n```ts\nwallet address: qbkJZTKQfcout2joWVmnvUrJUDTg93bhdv\n\n{\n  pagesTotal: 4,\n  txs: [\n    {\n      txid: 'f20914f3d810010c0a74df60abb3fcf0d3ff2669d944ce187f079ec9faec563e',\n      version: 1,\n      locktime: 0,\n      isqrc20Transfer: false,\n      vin: [Array],\n      vout: [Array],\n      blockhash: 'b993b80423233c4371c316e8d2eec6e0ea191efeb518fa3289f8ebce5cec8ab1',\n      blockheight: 171321,\n      confirmations: 2644,\n      time: 1530852864,\n      blocktime: 1530852864,\n      valueOut: 19.991,\n      size: 225,\n      valueIn: 20,\n      fees: 0.009\n    },\n    // ...\n  ]\n}\n```\n\n## toEncryptedPrivateKey\n\nencrypted wip using bip38.\n\nMethod signature:\n\n```ts\n/**\n * bip38 encrypted wip\n * @param passphrase\n * @param params scryptParams, default: { N: 16384, r: 8, p: 8 }\n */\npublic toEncryptedPrivateKey(\n  passphrase: string,\n  params: {N: number, r: number, p: number} = scryptParams,\n): string\n```\n\nExample:\n\n```ts\nconst network = networks.testnet;\nconst mnemonic =\n  \"hold struggle ready lonely august napkin enforce retire pipe where avoid drip\";\nconst password = \"covfefe\";\n\nconst wallet = network.fromMnemonic(mnemonic, password);\n\nconsole.log(\"public address:\", wallet.address);\nconsole.log(\"private key (WIF):\", wallet.toWIF());\nconsole.log(\n  \"encrypted bip38 private key is:\",\n  wallet.toEncryptedPrivateKey(password)\n);\n```\n\nExample output:\n\n```ts\npublic address: qLUHmrFGexxpyHwQphLpE1czZNFE5m1xmV\nprivate key (WIF): cNQKccYYQyGX9G9Qxq2DJev9jHygbZpb2UG7EvUapbtDx5XhkhYE\nencrypted bip38 private key is: 6PYVKJXXQ7eyTgGizw9NxX4nz1u185GqF28NWudxvyWZUh8QyJ9u2AqxWM\nencryption takes 2.214 seconds\n```\n\n## fromEncryptedPrivateKey\n\n`fromEncryptedPrivateKey` constructs a wallet from bip38 encrypted private key.\n\nMethod signature:\n\n```ts\n /**\n * constructs a wallet from bip38 encrypted private key\n * @param encrypted private key string\n * @param passhprase password\n * @param params scryptParams, default: { N: 16384, r: 8, p: 8 }\n */\npublic fromEncryptedPrivateKey(\n  encrypted: string,\n  passhprase: string,\n  params: {N: number, r: number, p: number} = scryptParams,\n): Wallet\n```\n\nExample:\n\n```ts\nconst network = networks.testnet;\nconst encrypted = \"6PYVKJXXQ7eyTgGizw9NxX4nz1u185GqF28NWudxvyWZUh8QyJ9u2AqxWM\";\nconst password = \"covfefe\";\n\nconst startAt = new Date().getTime();\nconst wallet = network.fromEncryptedPrivateKey(encrypted, password);\nconst endAt = new Date().getTime();\n\nconsole.log(\"public address:\", wallet.address);\nconsole.log(\"private key (WIF):\", wallet.toWIF());\nconsole.log(`decryption takes ${(endAt - startAt) / 1000} seconds`);\n```\n\nExample output:\n\n```ts\npublic address: qLUHmrFGexxpyHwQphLpE1czZNFE5m1xmV\nprivate key (WIF): cNQKccYYQyGX9G9Qxq2DJev9jHygbZpb2UG7EvUapbtDx5XhkhYE\ndecryption takes 2.258 seconds\n```\n\n## deriveChildWallet\n\nUse [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions) to derive child wallets from the current wallet's keypair.\n\nExample:\n\nGenerate as many child wallets as you need:\n\n```js\nconst childWallet0 = wallet.deriveChildWallet(0);\nconst childWallet1 = wallet.deriveChildWallet(1);\n```\n\nOr omit the child wallet index (defaults to 0):\n\n```js\n// The default child wallet index is 0\nconst childWallet = wallet.deriveChildWallet();\n```\n\n## scrypt (non-stable API)\n\nThis is an scrypt helper function, which may be removed in the future.\n\nTo use scrypt to hash a secret:\n\n```js\nimport { scrypt } from \"qtumjs-wallet\";\n\n// by default, the bip38 scrypt parameters are used\nconst hash = scrypt(\"my secret\", {\n  progress: status => {\n    console.log(\"status\", status);\n  }\n});\n\nconsole.log(hash);\n```\n\nThe progress callback is invoked every 1000 rounds. And finally the result hash is a hex string.\n\n```\nstatus { current: 257000, total: 262144, percent: 98.0377197265625 }\nstatus { current: 258000, total: 262144, percent: 98.419189453125 }\nstatus { current: 259000, total: 262144, percent: 98.8006591796875 }\nstatus { current: 260000, total: 262144, percent: 99.18212890625 }\nstatus { current: 261000, total: 262144, percent: 99.5635986328125 }\nstatus { current: 262000, total: 262144, percent: 99.945068359375 }\n\n8b41dd9e92490b8f2b01cbe1f20e2c57315b5f861da1ede1002bc544d90f7e56\n```\n\nYou may also choose to specify your own scrypt parameters:\n\n```js\nimport { scrypt, params } from \"qtumjs-wallet\";\n\nconst hash = scrypt(\"my secret\", {\n  params: {\n    N: 1 << 14,\n    r: 8,\n    p: 1\n  }\n});\n```\n","readmeFilename":"README.md"}