{"_id":"@astra-js/contract","_rev":"3-1754964ec40b436b83354d5265448479","name":"@astra-js/contract","dist-tags":{"latest":"0.1.59"},"versions":{"0.1.56":{"name":"@astra-js/contract","version":"0.1.56","description":"contract libraries 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"},"author":{"name":"neeboo@firestack.one"},"publishConfig":{"access":"public"},"license":"MIT","dependencies":{"@astra-js/account":"0.1.56","@astra-js/crypto":"0.1.56","@astra-js/network":"0.1.56","@astra-js/transaction":"0.1.56","@astra-js/utils":"0.1.56"},"gitHead":"56606e9365721729a490c27d6a294e0daf90fbdf","_id":"@astra-js/contract@0.1.56","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-O8ksgI/VjF2C9u2WvF7YiwiwCmbhc5OGd7Bfd3s8B6A71800/XrpPI3P/3ovV2GfLHSyb5esv3HInKaEI3hXXw==","shasum":"aa8f1b051c7025c0467465026b512d346c851972","tarball":"https://registry.npmjs.org/@astra-js/contract/-/contract-0.1.56.tgz","fileCount":28,"unpackedSize":15573003,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBWEZVcCP4XRo7GTtlfP63yQdaYDhEFotytdSmmdfYe7AiEA5S6qOG6jVGZvq1X/DJ3kMjG7ZOynnwhxe3Zn74gZh6E="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJifYzXACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqjLg//e1n9ReLWQpvayvpEpAkjTIg7kulwAAHHaIxO4I2woMHiFK8+\r\nIekl/p24lN5yHb+LdBWuQoTN8EV2ihDimHa795ce5jGZsmEHazma4bhPzUGS\r\nqJDeK9ci/dC9mhJb+SxjC+TGSzrXI3BtPP0QibIp7zg7uzDtDKrTjV5/ZfPQ\r\nyHrRKA+Tg2OW6XbmSgiyQfZf4PrPGAGWUbEQiMs+7HEjWiQBNJR9xZaLaHl4\r\ngr0EjFD4LhaZSoyyH07Z9grBt9mUwT6dmA3uXP1wZPjJkDfa6PtrXQzymrkT\r\nU3+PDp7hcMoSjOuxuoB9qBIGi7YNdpgZgJOriQ8NRawy+L26eqVSZ9irDKRQ\r\ngNR0CS1M0ZZhZOXOj+AfMAuF1+R2SWqT30vWjpXcD+jGIdm1PDw4iwdDZMb9\r\nDQL3QXqX/o105+/3nNc19kkak/lOLjqxKunRSXVmobqiQ2ztNaHQ3ivb9aFs\r\n1Q0ABTKdbj+8Eq9VrD6h6EmlwKB2l8CAw8HYcb3cQauXneN0iMMr0bOjBbGD\r\nh7FnsVNI9LgkVelEPceZyVceTTPFG92WUQNqhAIj4LGi4pKX/9hgZ9pJf1Qf\r\nq6xKH4tW6TSVk6nfYqD/aAeX/5OeZGp6ATaO37u30+NBphpAOw94of6nM1Oq\r\nlvrP3RSkC+RoHL7HX2zoUeJ35EKnlb7rVn0=\r\n=ekhv\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/contract_0.1.56_1652395223504_0.6241613230899319"},"_hasShrinkwrap":false},"0.1.57":{"name":"@astra-js/contract","version":"0.1.57","description":"contract libraries 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"},"author":{"name":"neeboo@firestack.one"},"publishConfig":{"access":"public"},"license":"MIT","dependencies":{"@astra-js/account":"0.1.57","@astra-js/crypto":"0.1.56","@astra-js/network":"0.1.56","@astra-js/transaction":"0.1.56","@astra-js/utils":"0.1.56"},"gitHead":"56606e9365721729a490c27d6a294e0daf90fbdf","_id":"@astra-js/contract@0.1.57","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-RzNVBMroJDMkaeWtsRf4fq6VusRb9jrEFdxDipAsMTtbOPbDnrE4pukhkpeF/9vGiYixiB8dmxrwHyQKwuLXDw==","shasum":"81504ce0055ad0ab189bbd0fe97696d2321fcbeb","tarball":"https://registry.npmjs.org/@astra-js/contract/-/contract-0.1.57.tgz","fileCount":28,"unpackedSize":15573003,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGTEk2j+VV/j4xTjyVtv88wdMMoW2bWciV36nOoJqZVHAiB1Lx6CMdy5Th7rMkNOqXa4IwxtK1QLD3lXkgOJY+s/sg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJigmutACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpw6hAAjB2bRfposn/GrI6WUYxg3oe5PVvg4k4OIfK9cHNWF39CQoci\r\nJTmtk8U4g/Kysnhzf6s3mHrFJOuoq6RmyByHpnzBsjc/2EBROvw342EZicAI\r\nzrtsQofBgVZa0gNof5K4i6MwN4YNfj4dYn1+gWWqP/Slh2PBfUTdfq6gUW7D\r\nRdESLX1It3iUWCb/wjaAEw+XgiwE5Q7tUXsYMAI1IDd91Zr4hyRM7PRyvpoy\r\n8GdFDiB76W6b4PtEWBjC64loIag/i/K20nIQa6OHfY0zVbELUUFmyPu4Ndq2\r\nv2aD4a87Eotyw9lRpIIEpLSMWZyOr4LKPBE31nF6gqrt/FG98LJM9+ha9Bzq\r\n2N+W9wwzhno3x9qMeImme7l4slKKhAlGh6VsRfcqrpIXL44Iwpr+VjMYowiJ\r\nyM7qXVDTWZkEtvK9RlnSUXATxIQgkoVP53mQJBefQnsfKynGc9W0I3mi/fmB\r\nwKSc4x1Kwb1QoWcXevYWONYal6Ygaj3AUtuA2s/Tdx67TOmXekf1TW+K6hXU\r\nRy4AM+dHKTwwyJb3ZOX189UtBmzywCyfx3DelidGGDILRDQ4jEwoiKBjAqkc\r\nq+tuOhbyQB04CypRytdZqjXnC/vCsK4bow6VgtLghpS4rdq0BZIVl6RM1hwQ\r\nM6d5oeEvD/SZF59lTEIyEe3rC67NxFOmmuU=\r\n=ETFL\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/contract_0.1.57_1652714412816_0.5109274146931995"},"_hasShrinkwrap":false},"0.1.59":{"name":"@astra-js/contract","version":"0.1.59","description":"contract libraries 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"},"author":{"name":"neeboo@firestack.one"},"publishConfig":{"access":"public"},"license":"MIT","dependencies":{"@astra-js/account":"0.1.59","@astra-js/crypto":"0.1.59","@astra-js/network":"0.1.59","@astra-js/transaction":"0.1.59","@astra-js/utils":"0.1.59"},"gitHead":"552a541e743583dc30ce1d5312e34895c4f1c3c5","_id":"@astra-js/contract@0.1.59","_nodeVersion":"16.15.0","_npmVersion":"lerna/3.22.1/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-2w0EmAb6LGpIAd20vOgD8O/8sf8+C0d35G7Mc/Y1uiCvTvi1kjhrhJ51HIuPJ1HShjOf3ZhPf/G8Hf9VBIFZyA==","shasum":"175708946827e23b7a99115d975521d63b8221d2","tarball":"https://registry.npmjs.org/@astra-js/contract/-/contract-0.1.59.tgz","fileCount":108,"unpackedSize":15783342,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDJytf4WO5ehlaoiHdsXuqDMXX9PmBBitwWgjTIhzGFiAiBP05s+sUBpmpdx+lUF5Sw28hTxankyUR4jyxQ17RzlAQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJig9yHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq1hQ/+IG9AnAGnI5qFs9YFTc3ZAP6LvgSVcn1nG6Ojak8NDC11ocYw\r\nMQXvy5ffdqMNczq/VckSvJCgol4qJYnFH+CLRqlivgh5HY8GhC3K4qKQlw7R\r\nfvoQulqfo6w4Bvo9/EAEbyUrJoY1jM0ic0bckCZ0Jb1UeClRlB8YdFkWD98g\r\nrA0b9O4XWxPITmXwSO4yNMGony/KeG0kTO6+vyc6NHp0p4VMnUYcqNf1G6pW\r\nn9x5BjWDgESYnnugK0N4QEjcQZ/WFjtJA7YbUgdeMCAq/r/00nvx7ZSh2QIR\r\nuyyVY/jEo+Yvo1ULMCDhN83OnHAxNKI/7HAmC0pFEfyxj7TLyxqXcT/WZemB\r\n5OzL5oOttEnemb1qZgLNh6ap69fWKMFgwyHQj4pYDp6boNP6C6WZBXzTSnDs\r\nJ7VemMas0aoFIkpoFhuFZkSaXrOf+Nh9Ux9hHsS8x9HL7E1RjsA7ldCHuqK4\r\nn9BcyWlVtHUCj9k9iSS2znjE5vhWOHmh+VlazAhAkTRmXVL7mriDpnm8S+aF\r\nb8j1SEp8QXXVioriLKLuMsBi02DVZG0Ht4rB3PQzWBzsOCBGOefSrywpXLKz\r\n64X79M7jSyhCF97etYNHv+20WHETHT1nR/3xoutqvSsyia/J7H28VoRqW/Mq\r\nhKDVz3VS12XvFAVS8JIyBNL4HJyRhMdcbl8=\r\n=SFs/\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/contract_0.1.59_1652808838846_0.8682447372512376"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-12T22:40:23.440Z","0.1.56":"2022-05-12T22:40:23.804Z","modified":"2022-05-17T17:33:59.223Z","0.1.57":"2022-05-16T15:20:13.249Z","0.1.59":"2022-05-17T17:33:59.116Z"},"maintainers":[{"name":"astra-network","email":"contact@astranetwork.com"}],"description":"contract libraries for astra","author":{"name":"neeboo@firestack.one"},"license":"MIT","readme":"# @astra-js/contract\n\nThis package provides a collection of apis to create, deploy, and interact with smart contracts. In Astra, smart contracts all fully EVM compatible and the formats and terminologies match 1-to-1 with EVM smart contracts.\n\n## Installation\n\n```\nnpm install @astra-js/contract\n```\n\n## Usage\n\nDeploying a contract using `contractConstructor`\n```javascript\nconst { ContractFactory } = require('@astra-js/contract');\nconst { Wallet } = require('@astra-js/account');\nconst { Messenger, HttpProvider } = require('@astra-js/network');\nconst { ChainID, ChainType, hexToNumber } = require('@astra-js/utils');\n\nconst wallet = new Wallet(\n  new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\nconst factory = new ContractFactory(wallet);\n\nconst contractJson = require(\"./Counter.json\");\nconst contract = factory.createContract(contractJson.abi);\n\nconst options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000\nlet options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas\n\nconst options3 = { data: contractJson.bytecode }; // contractConstructor needs contract bytecode to deploy\n\ncontract.wallet.addByPrivateKey('1f054c21a0f57ebc402c00e14bd1707ddf45542d4ed9989933dbefc4ea96ca68');\n\ncontract.methods.contractConstructor(options3).estimateGas(options1).then(gas => {\n  options2 = {...options2, gasLimit: hexToNumber(gas)};\n  contract.methods.contractConstructor(options3).send(options2).then(response => {\n    console.log('contract deployed at ' + response.transaction.receipt.contractAddress);\n  });\n});\n```\nInstead of `contract.methods.contractConstructor`, `contract.deploy` could be used and it will work.\n\nLoading a contract object using the contract json and contract address for interacting with it\n```javascript\nconst { Astra } = require(\"@astra-js/core\");\nconst { ChainID, ChainType } = require(\"@astra-js/utils\");\nconst astra = new Astra(\"https://rpc.s0.t.astranetwork.com\", {\n  chainType: ChainType.Astra,\n  chainId: ChainID.AstraTestnet,\n});\n\nconst contractJson = require(\"./Counter.json\");\nconst contractAddr = \"0x19f64050e6b2d376e52AC426E366c49EEb0724B1\";\n\nconst contract = astra.contracts.createContract(contractJson.abi, contractAddr);\nconsole.log(contract.methods);\n```\n\nDirectly loading contract using `ContractFactory`\n```javascript\nconst { ContractFactory } = require('@astra-js/contract');\nconst { Wallet } = require('@astra-js/account');\nconst { Messenger, HttpProvider } = require('@astra-js/network');\nconst { ChainID, ChainType, hexToNumber } = require('@astra-js/utils');\n\nconst wallet = new Wallet(new Messenger(\n  new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n  ChainType.Astra,\n  ChainID.AstraTestnet,\n));\nconst factory = new ContractFactory(wallet);\nconst contract = factory.createContract(contractJson.abi, contractAddr);\n```\n\nEstimate gas for contract methods\n```javascript\nconst options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000\n\ncontract.methods.getCount().estimateGas(options1).then(gas => {\n  console.log('gas required for getCount is ' + hexToNumber(gas));\n});\n```\n\nCall contract read-only methods. Astra uses 1 Gwei gas price and gas limit of 21000 by default. Use the estimate gas api to correctly set the gas limit.\n```javascript\nconst options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000\nlet options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas\n\ncontract.methods.getCount().estimateGas(options1).then(gas => {\n  options2 = {...options2, gasLimit: hexToNumber(gas)};\n  contract.methods.getCount().call(options2).then(count => {\n    console.log('counter value: ' + count);\n  });\n});\n```\n\nInvoking contract modification methods using `send` api. Need to add a signing account to the contract wallet, otherwise `send` api will not work.\n```javascript\nconst options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000\nlet options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas\n\ncontract.wallet.addByPrivateKey('1f054c21a0f57ebc402c00e14bd1707ddf45542d4ed9989933dbefc4ea96ca68');\n\ncontract.methods.incrementCounter().estimateGas(options1).then(gas => {\n  options2 = {...options2, gasLimit: hexToNumber(gas)};\n  contract.methods.incrementCounter().send(options2).then(response => {\n    console.log(response.transaction.receipt);\n  });\n});\n```\n\nAll the above apis can also be asynchronously executed using `async` and `await`.\n\nSubscribing to the contract events requires web socket based messenger.\n```javascript\nconst { ContractFactory } = require('@astra-js/contract');\nconst { Wallet } = require('@astra-js/account');\nconst { Messenger, WSProvider } = require('@astra-js/network');\nconst { ChainID, ChainType, hexToNumber } = require('@astra-js/utils');\nconst ws = new WSProvider('wss://ws.s0.t.astranetwork.com');\n\nconst wallet = new Wallet(\n  new Messenger(\n    ws,\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\nconst factory = new ContractFactory(wallet);\n\nconst contractJson = require(\"./Counter.json\");\nconst contractAddr = '0x8ada52172abda19b9838eb00498a40952be6a019';\n\nconst contract = factory.createContract(contractJson.abi, contractAddr);\n\ncontract.events\n  .IncrementedBy()\n  .on('data', (event) => {\n    console.log(event);\n  })\n  .on('error', console.error);\n```","readmeFilename":"README.md"}