{"_id":"@astra-js/transaction","_rev":"2-ebc327d7be092c6f395a65df7db4012d","name":"@astra-js/transaction","dist-tags":{"latest":"0.1.59"},"versions":{"0.1.56":{"name":"@astra-js/transaction","version":"0.1.56","description":"transaction package for astra","main":"dist/index.js","node":"dist/index.js","browser":"dist/index.js","module":"dist/index.esm.js","jsnext:main":"dist/index.esm.js","typings":"dist/index.d.ts","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"publishConfig":{"access":"public"},"author":{"name":"neeboo@firestack.one"},"license":"MIT","dependencies":{"@astra-js/crypto":"0.1.56","@astra-js/network":"0.1.56","@astra-js/utils":"0.1.56"},"gitHead":"56606e9365721729a490c27d6a294e0daf90fbdf","_id":"@astra-js/transaction@0.1.56","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-/rP7SV4Yc8iaeEQA68jvbKZHXyWMKgB2GQiAP2asmMyHeD4Y0qy3MkP3lkPuqMfW3Cg91yhfpYeWywL2pi6HHw==","shasum":"959b867ea398843706ec2fb7646d9f4bf12069af","tarball":"https://registry.npmjs.org/@astra-js/transaction/-/transaction-0.1.56.tgz","fileCount":18,"unpackedSize":253295,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD8JRvHBNo39aefwyWJ5GwR4L3KkbTsEDyftNFgDHJQ9gIgdGpzY/Ymc1FTrKR6Kb8mXYa6eGEzoGCozYktVqqtNNg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJifYz0ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpOLA//XlQ46Wgi5A7Pvlo0OPqHynBK9Ip2kZnL73jcboDFk6LDAflr\r\nck+QOp5nnd2kM94OvK+93DLT3J14rSUPla83cbVAMPM0Q9uS5A3x2GsoZ/WS\r\nAgvipMDc1J0uK+Rm1lhNhoJA2/Fgu/jM0Z2H93Qg80u4KoywuhBsFmBbyn73\r\nzuE2LMojoe2nRCZj6pf3JW3+47CDROlXMDmmLFGAIVkLdeMSvdQQUAbugZOS\r\nzUbMlbym10BlI1CzuU8ziHkh3QFRZVewTDswieuuEfgKLc6mUq1sHv/SGsdc\r\nF1EoFn40euVv9fyERD4ne5cx5xN3OjOneZTsxcLj7mxT33v+8YTLPyBQF2Nf\r\nGmv0IKeRmOZq61IFqDXlMS06cF6+tf1YqnVILBXxYB8QZVB70mOLoNhGJ4Hg\r\n63lbypMlRKsu86HBvelBrMEsNyDYT8AImsD/fmIpOdAxZB+OgwmiZyIdJBk0\r\nfmBeqFfqG0IumO31VSaLJ94wWSCgJpUc1aguSCghSdElfUucIgQOaYla1GVX\r\ndMRbNYmczv3rOq5qCeMtacNh8K2PQexPSXQWzClZ1FU4n6+khTGyL10r5kcP\r\n3szMvIa8NeI3fQFn/IPjJioekN58yoVT1D0TJddAqE7M0Zd8F41q2Lipmmzj\r\ncP7a1EyyLn0zheCJ//RCPPQoTUcUDYqrhIc=\r\n=aVG/\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"astra-js","email":"contact@astranetwork.com"},"directories":{},"maintainers":[{"name":"astra-js","email":"contact@astranetwork.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/transaction_0.1.56_1652395251931_0.5349868486237028"},"_hasShrinkwrap":false},"0.1.59":{"name":"@astra-js/transaction","version":"0.1.59","description":"transaction package for astra","main":"dist/index.js","node":"dist/index.js","browser":"dist/index.js","module":"dist/index.esm.js","jsnext:main":"dist/index.esm.js","typings":"dist/index.d.ts","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"publishConfig":{"access":"public"},"author":{"name":"neeboo@firestack.one"},"license":"MIT","dependencies":{"@astra-js/crypto":"0.1.59","@astra-js/network":"0.1.59","@astra-js/utils":"0.1.59"},"gitHead":"552a541e743583dc30ce1d5312e34895c4f1c3c5","_id":"@astra-js/transaction@0.1.59","_nodeVersion":"16.15.0","_npmVersion":"lerna/3.22.1/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-eLsJlLuuh8VBXM8I/Y+pHErKEg6xj/KlZJJRemf/oNCibEWhnDl0M1JhVNrnRXcF+3/c2QNerggFGw/0Ne0Fyg==","shasum":"b867c433daeb51ef7793e5c7dadbad15a40bd74b","tarball":"https://registry.npmjs.org/@astra-js/transaction/-/transaction-0.1.59.tgz","fileCount":50,"unpackedSize":370554,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCOfDYpST3MIKRB/+ABjqgonLZnZOQgEY3iutLuHXfrggIgM8cyuZc2FSSn+iimKIEjHP837NQnKJqmaRaoyLl0wNs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJig9yEACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpbEw//atUoQ/lEYRuy1ThalX/kG6BQQvCA0yaTux+U9qq4EJS/NBW7\r\n0Xn/QlhIvUAy8OQSnuZCTufsWzaP5kztu2+JBiNoNbps+sKgefp/CCeP4Ks8\r\nRuigbPPJtW5rasXt8yawO3eBN1G0zjQH7p9eqFs/xpF70+UWI1jnz8U58XfJ\r\nyr1F/el00S7wCRdfbFc/4+bp7sydLRtxWwiJCqK6P2s45jOmM3aGccW0wh2M\r\nYQH2KyrTcU3M46HNn2C8pwEl92pg1exximpKDyqqNRmeX8b5U50UBuJjfHpB\r\nej79+OBgdQBm3lRB6mSX1xNNCbFDjqVPcpBjLiQQklvAoSEMKnHndgbC7G6M\r\nF3PsoRgCZz+DIdlP65295eZL8k2tOgLc4qlLQM7Dm8GZLVw7Lmklool8lp2O\r\n6aWkLeSvWPemRgSb8YxrRlNjRgDr821b8zxlw+C61EU1zsS+K5FX7oBCmq8Y\r\n24BlXBKINGrOaIcQqUeO06brcdUl1U8/beqUGMy3InzHPrzgrE18hoFnEUKy\r\nZ8OxQLPhsscSvnJFRd0qgTpBDtwnNKX2MQQ2E5ONyRx1to5D1H0piptRX96q\r\nc3C6XhrRdEZbJ4R7g0HsFSSwemZRqpGmExCLJih1Ppy70juRoCexCc3boYkR\r\nnJCL6jIL0s4JFYbYZKT2p+eOHA5eD2K2Sds=\r\n=RVtK\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"astra-network","email":"contact@astranetwork.com"},"directories":{},"maintainers":[{"name":"astra-network","email":"contact@astranetwork.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/transaction_0.1.59_1652808835951_0.07080599115525454"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-12T22:40:51.873Z","0.1.56":"2022-05-12T22:40:52.085Z","modified":"2022-05-17T17:33:56.219Z","0.1.59":"2022-05-17T17:33:56.143Z"},"maintainers":[{"name":"astra-network","email":"contact@astranetwork.com"}],"description":"transaction package for astra","author":{"name":"neeboo@firestack.one"},"license":"MIT","readme":"# @astra-js/transaction\n\nThis package provides a collection of apis to create, sign/send transaction, and receive confirm/receipt.\n\n## Installation\n\n```\nnpm install @astra-js/transaction\n```\n\n## Usage\n\nCreate a Astra instance connecting to testnet\n\n```javascript\nconst { Astra } = require('@astra-js/core');\nconst {\n  ChainID,\n  ChainType,\n  hexToNumber,\n  numberToHex,\n  fromWei,\n  Units,\n  Unit,\n} = require('@astra-js/utils');\n\nconst astra = new Astra(\n    'https://rpc.s0.t.astranetwork.com/',\n    {\n        chainType: ChainType.Astra,\n        chainId: ChainID.AstraTestnet,\n    },\n);\n```\n\nCreating a new transaction using parameters\n```javascript\nconst txn = astra.transactions.newTx({\n  to: '0xd6ba69DA5b45eC98b53e3258d7DE756a567B6763',\n  value: new Unit(1).asOne().toWei(),\n  // gas limit, you can use string\n  gasLimit: '21000',\n  // send token from shardID\n  shardID: 0,\n  // send token to toShardID\n  toShardID: 0,\n  // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN\n  gasPrice: new astra.utils.Unit('1').asGwei().toWei(),\n});\n```\n\nRecovering transaction from raw transaction hash\n```javascript\nconst raw = '0xf86d21843b9aca00825208808094d6ba69da5b45ec98b53e3258d7de756a567b6763880de0b6b3a76400008028a0da8887719f377401963407fc1d82d2ab52404600cf7bea37c27bd2dfd7c86aaaa03c405b0843394442b303256a804bde835821a8a77bd88a2ced9ffdc8b0a409e9';\nconst tx = astra.transactions.recover(raw);\n```\n\nGetting the RLP encoding of a transaction (rawTransaction), along with raw transaction field values that were encoded\n```javascript\nconst [encoded, raw] = txn.getRLPUnsigned()\n```\n\nSign the transaction using a wallet and send the transaction, wait for confirmation and print receipt\n```javascript\n// key corresponds to 0xFF9a025FdC0fd4b68Ba4e9Bff46476de15ED8f4D, only has testnet balance\nastra.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');\n\nastra.wallet.signTransaction(txn).then(signedTxn => {\n  signedTxn.sendTransaction().then(([tx, hash]) => {\n    console.log('tx hash: ' + hash);\n    signedTxn.confirm(hash).then(response => {\n      console.log(response.receipt);\n    });\n  });\n});\n```\n\nAsynchronous transaction sign, send, and confirm\n```javascript\nasync function transfer() {\n  astra.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');\n\n  const signedTxn = await astra.wallet.signTransaction(txn);\n  signedTxn\n    .observed()\n    .on('transactionHash', (txnHash) => {\n      console.log('');\n      console.log('--- hash ---');\n      console.log('');\n      console.log(txnHash);\n      console.log('');\n    })\n    .on('receipt', (receipt) => {\n      console.log('');\n      console.log('--- receipt ---');\n      console.log('');\n      console.log(receipt);\n      console.log('');\n    })\n    .on('cxReceipt', (receipt) => {\n      console.log('');\n      console.log('--- cxReceipt ---');\n      console.log('');\n      console.log(receipt);\n      console.log('');\n    })\n    .on('error', (error) => {\n      console.log('');\n      console.log('--- error ---');\n      console.log('');\n      console.log(error);\n      console.log('');\n    });\n\n  const [sentTxn, txnHash] = await signedTxn.sendTransaction();\n\n  const confiremdTxn = await sentTxn.confirm(txnHash);\n\n  // if the transactino is cross-shard transaction\n  if (!confiremdTxn.isCrossShard()) {\n    if (confiremdTxn.isConfirmed()) {\n      console.log('--- Result ---');\n      console.log('');\n      console.log('Normal transaction');\n      console.log(`${txnHash} is confirmed`);\n      console.log('');\n      console.log('please see detail in explorer:');\n      console.log('');\n      console.log('https://explorer.testnet.astra.one/#/tx/' + txnHash);\n      console.log('');\n      process.exit();\n    }\n  }\n  if (confiremdTxn.isConfirmed() && confiremdTxn.isCxConfirmed()) {\n    console.log('--- Result ---');\n    console.log('');\n    console.log('Cross-Shard transaction');\n    console.log(`${txnHash} is confirmed`);\n    console.log('');\n    console.log('please see detail in explorer:');\n    console.log('');\n    console.log('https://explorer.testnet.astra.one/#/tx/' + txnHash);\n    console.log('');\n    process.exit();\n  }\n}\ntransfer();\n```\n\n\n\n","readmeFilename":"README.md"}