{"_id":"@ahmedueig/web3-tools","_rev":"1-e282e971e8a79dba7ff7f1ab2e65bd4b","name":"@ahmedueig/web3-tools","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.3":{"name":"@ahmedueig/web3-tools","version":"1.0.3","description":"Htmlcoin JavaScript API comunicating to htmlcoin node over RPC","main":"./src/index.js","repository":{"type":"git","url":"git+https://github.com/ahmedueig/web3-tools.js.git"},"license":"LGPL-3.0","directories":{"lib":"./lib"},"engines":{"node":">=16","npm":">=6"},"dependencies":{"axios":"^0.18.0","bignumber.js":"^7.2.1","bn.js":"^4.11.8","bs58":"^4.0.1","chai":"^4.1.2","ethjs-abi":"^0.2.1","lodash":"^4.17.10","utf8":"^3.0.0","web3-utils":"^1.0.0-beta.36"},"devDependencies":{"dotenv":"^6.0.0","eslint":"^4.19.1","eslint-config-airbnb-base":"^12.1.0","eslint-plugin-import":"^2.14.0","eslint-plugin-jsx-a11y":"^6.1.1","husky":"^1.0.0-rc.13","mocha":"^5.2.0"},"scripts":{"lint":"eslint -- src/. test/.","lint:fix":"eslint --fix -- src/. test/.","test":"echo `test`","test:cleanenv":"mocha --recursive **/*.tests.js --cleanenv"},"husky":{"hooks":{"pre-push":"npm run lint:fix"}},"homepage":"https://github.com/ahmedueig/web3-tools.js","bugs":{"url":"https://github.com/ahmedueig/web3-tools/issues"},"keywords":["htmlcoin","althash","javascript","jsonrpc"],"author":{"name":"ahmedueig"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_id":"@ahmedueig/web3-tools@1.0.3","gitHead":"4acfdd6696ab7b1e944b9eb64994561fba60946f","_nodeVersion":"18.19.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-toqz1mlzUJgDzSsWXtwxfJl5uxaXHX4g8JVfTIbjOTOTqeX4ERpbJvkZ9MFx96l8gozBNgE+KUvYakydX6XkAA==","shasum":"82ab16991f3c3ff71122e30185f84c77c1c96f46","tarball":"https://registry.npmjs.org/@ahmedueig/web3-tools/-/web3-tools-1.0.3.tgz","fileCount":25,"unpackedSize":320931,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEiQofzP15k4QTdS/2aGD4kOQNN0aAyFmOB2TrJyH2cHAiAcn0pwdY5knDoIbnN18eMeBYiLxuXJdwVSqR2GZPlv/A=="}]},"_npmUser":{"name":"ahmedueig","email":"ahmedueig@gmail.com"},"maintainers":[{"name":"ahmedueig","email":"ahmedueig@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/web3-tools_1.0.3_1709368960634_0.446784772611166"},"_hasShrinkwrap":false},"1.0.4":{"name":"@ahmedueig/web3-tools","version":"1.0.4","description":"Htmlcoin JavaScript API comunicating to htmlcoin node over RPC","main":"./src/index.js","repository":{"type":"git","url":"git+https://github.com/ahmedueig/web3-tools.js.git"},"license":"LGPL-3.0","directories":{"lib":"./lib"},"engines":{"node":">=16","npm":">=6"},"dependencies":{"axios":"^0.18.0","bignumber.js":"^7.2.1","bn.js":"^4.11.8","bs58":"^4.0.1","chai":"^4.1.2","ethjs-abi":"^0.2.1","lodash":"^4.17.10","utf8":"^3.0.0","web3-utils":"^1.0.0-beta.36","eslint":"^8.20.0","eslint-import-resolver-typescript":"^3.5.5","eslint-plugin-require-extensions":"^0.1.3","http-browserify":"^1.7.0","https-browserify":"^1.0.0","husky":"^8.0.3","jest":"^29.7.0","@jacktanws/web3-kit":"1.6.3","de-web3":"2.0.5"},"devDependencies":{"dotenv":"^6.0.0","eslint":"^4.19.1","eslint-config-airbnb-base":"^12.1.0","eslint-plugin-import":"^2.14.0","eslint-plugin-jsx-a11y":"^6.1.1","husky":"^1.0.0-rc.13","mocha":"^5.2.0"},"scripts":{"lint":"eslint -- src/. test/.","lint:fix":"eslint --fix -- src/. test/.","test":"echo `test`","test:cleanenv":"mocha --recursive **/*.tests.js --cleanenv"},"husky":{"hooks":{"pre-push":"npm run lint:fix"}},"homepage":"https://github.com/ahmedueig/web3-tools.js","bugs":{"url":"https://github.com/ahmedueig/web3-tools/issues"},"keywords":["htmlcoin","althash","javascript","jsonrpc"],"author":{"name":"ahmedueig"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_id":"@ahmedueig/web3-tools@1.0.4","gitHead":"b10e5f0836cad583d6af68c90db75e29c10f04d8","_nodeVersion":"18.19.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-zNiDrauVKQ9fup2+qguoYObN6qWZ9WUh1tbN2OKaWTa2hqqcDlNKkxuiNQvFN3KwJHGM1f+2dfhz5tB9e9GLHw==","shasum":"85395a67b050ae7f471e68025a7c04480a66b32e","tarball":"https://registry.npmjs.org/@ahmedueig/web3-tools/-/web3-tools-1.0.4.tgz","fileCount":26,"unpackedSize":321944,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCAaDXz9mLAp81oOj9HaC/NtZXqhc3frdABE8/Js7iuGAIhAKN/vrQIz10wIXnofOvOejeIARN+tmTfqgfHqlgFtFz3"}]},"_npmUser":{"name":"ahmedueig","email":"ahmedueig@gmail.com"},"maintainers":[{"name":"ahmedueig","email":"ahmedueig@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/web3-tools_1.0.4_1709645706998_0.4921588410221469"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-02T08:42:40.545Z","1.0.3":"2024-03-02T08:42:40.793Z","modified":"2024-03-05T13:35:07.609Z","1.0.4":"2024-03-05T13:35:07.175Z"},"maintainers":[{"name":"ahmedueig","email":"ahmedueig@gmail.com"}],"description":"Htmlcoin JavaScript API comunicating to htmlcoin node over RPC","homepage":"https://github.com/ahmedueig/web3-tools.js","keywords":["htmlcoin","althash","javascript","jsonrpc"],"repository":{"type":"git","url":"git+https://github.com/ahmedueig/web3-tools.js.git"},"author":{"name":"ahmedueig"},"bugs":{"url":"https://github.com/ahmedueig/web3-tools/issues"},"license":"LGPL-3.0","readme":"# web3-tools.js - Web3.js for Htmlcoin\n\nweb3-tools is a library for dApps to interract with the Htmlcoin blockchain. web3-tools communicates to a Htmlcoin node via the provider provided.\n\nhttps://www.npmjs.com/package/web3-tools\n\n## Get Started\nRun the following in your project folder:\n\n\tnpm install web3-tools --save\n\n## Web Dapp Usage\nThis is example is meant for web dapps who would like to use web3-tools's convenience methods with HtmlcoinChrome's RPC provider. HtmlcoinChrome is a Htmlcoin wallet [Chrome extension](). More details about HtmlcoinChrome [here](https://github.com/denuoweb/htmlcoin-chrome-wallet).\n\n### 1. Construct web3-tools instance\nIf you have HtmlcoinChrome installed, you will have a `window.htmlcoinchrome` object injected in your browser tab. Pass that into web3-tools as a parameter to set the provider.\n```\nconst web3-tools = new web3-tools(window.htmlcoinchrome.rpcProvider);\n```\n\n### 2. Construct Contract instance\nThe Contract class is meant for executing `sendtocontract` or `callcontract` at a specific contract address with a given ABI.\n```\nconst contractAddress = 'f7b958eac2bdaca0f225b86d162f263441d23c19';\nconst contractAbi = [{\"constant\":false,\"inputs\":[{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_lastResultIndex\",\"type\":\"uint8\"},{\"name\":\"_arbitrationEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"createDecentralizedOracle\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_lastResultIndex\",\"type\":\"uint8\"},{\"name\":\"_arbitrationEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"doesDecentralizedOracleExist\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_oracle\",\"type\":\"address\"},{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_bettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_resultSettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"createCentralizedOracle\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_oracle\",\"type\":\"address\"},{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_bettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_resultSettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"doesCentralizedOracleExist\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"oracles\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_addressManager\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_contractAddress\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_oracle\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_eventAddress\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_name\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_resultNames\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"_bettingEndBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_resultSettingEndBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"CentralizedOracleCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_contractAddress\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_eventAddress\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_name\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_resultNames\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"_lastResultIndex\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"_arbitrationEndBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"DecentralizedOracleCreated\",\"type\":\"event\"}];\n\n// Create a new Contract instance and use the same provider as web3-tools\nconst contract = web3-tools.Contract(contractAddress, contractAbi);\n```\n\n### 3. Get Logged In HtmlcoinChrome Account\nTo get the current logged in account in HtmlcoinChrome, you will have to add an [Event Listener](https://www.w3schools.com/jsref/met_element_addeventlistener.asp) to listen to messages sent from HtmlcoinChrome.\n```\nlet account;\n\nfunction onHtmlcoinchromeAcctChange(event) {\n  if (event.data.message && event.data.message.type == \"ACCOUNT_CHANGED\") {\n    account = event.data.message.payload;\n\n    // You now have the logged in account.\n    // account = InpageAccount {\n    //   loggedIn: true,\n    //   name: \"My Wallet\", \n    //   network: \"TestNet\",\n    //   address: \"hJHp6dUSmDShpEEMmwxqHPo7sFSdydSkPM\",\n    //   balance: 49.10998413\n    // } \n\n    // You may also get the account from `window.htmlcoinchrome.account`.\n    // account = window.htmlcoinchrome.account\n  }\n}\nwindow.addEventListener('message', onHtmlcoinchromeAcctChange, false);\n```\n\n### 4. Execute sendtocontract\nThe last piece is to execute a `sendtocontract` on your Contract instance. This will automatically show a HtmlcoinChrome popup to confirm that you would like to send the transaction.\n```\n// Does a sendtocontract call on a function called setResult(uint8)\nconst tx = await contract.send('setResult', {\n  methodArgs: [1],    // Sets the function params\n  gasLimit: 1000000,  // Sets the gas limit to 1 million\n  senderAddress: account.address,\n});\n// tx = txid of the transaction\n```\n\n## web3-toolsProvider\nThe provider is the link between web3-tools and the blockchain. A compatible web3-tools Provider adheres to the following interface:\n```\ninterface web3-toolsProvider: {\n  rawCall: (method: string, args: any[]) => Promise; // returns the result of the request\n}\n```\n\n## web3-tools\nInstantiate a new instance of `web3-tools`: \n```\nconst { web3-tools } = require('web3-tools');\n\n// Instantiate web3-tools with HttpProvider\n// Pass in the URL of your Htmlcoin node RPC port with auth credentials.\n// Default Htmlcoin RPC ports: testnet=14889 mainnet=4889\nconst web3-tools = new web3-tools('http://htmlcoin:htmlcoin@localhost:14889');\n\n// Instantiate web3-tools with HtmlcoinchromeRPCProvider\n// HtmlcoinchromeRPCProvider is a provider for the HtmlcoinChrome Wallet Extension.\n// Please note HtmlcoinchromeRPCProvider only allows the rawCall() method to be used.\n// It is specifically used for `sendtocontract` and `callcontract` only.\nconst web3-tools = new web3-tools(window.htmlcoinchrome.rpcProvider);\n```\n\n### isConnected()\nChecks if you are connected properly to the local htmlcoin node.\n```\nasync function isConnected() {\n  return await web3-tools.isConnected();\n}\n```\n\n### getHexAddress(address)\nConverts a Htmlcoin address to hex format.\n```\nasync function getHexAddress() {\n  return await web3-tools.getHexAddress('hKjn4fStBaAtwGiwueJf9qFxgpbAvf1xAy');\n}\n```\n\n### fromHexAddress(hexAddress)\nConverts a hex address to Htmlcoin format.\n```\nasync function fromHexAddress() {\n  return await web3-tools.fromHexAddress('17e7888aa7412a735f336d2f6d784caefabb6fa3');\n}\n```\n\n### getBlockCount()\nGets the current block height of your local Htmlcoin node.\n```\nasync function getBlockCount() {\n  return await web3-tools.getBlockCount();\n}\n```\n\n### getTransaction(txid)\nGets the transaction details of the transaction id.\n```\nasync function getTransaction(args) {\n  const {\n    transactionId, // string\n  } = args;\n\n  return await web3-tools.getTransactionReceipt(transactionId);\n}\n```\n\n### getTransactionReceipt(txid)\nGets the transaction receipt of the transaction id.\n```\nasync function getTransactionReceipt(args) {\n  const {\n    transactionId, // string\n  } = args;\n\n  return await web3-tools.getTransactionReceipt(transactionId);\n}\n```\n\n### listUnspent()\nGets the unspent outputs that can be used.\n```\nasync function listUnspent() {\n  return await web3-tools.listUnspent();\n}\n```\n\n### searchLogs(fromBlock, toBlock, addresses, topics, contractMetadata, removeHexPrefix)\nGets the logs given the params on the blockchain.\n\nThe `contractMetadata` param contains the contract names and ABI that you would like to parse. An example of one is:\n```\n# contract_metadata.js\nmodule.exports = {\n  EventFactory: {\n    address: 'd53927df927be7fc51ce8bf8b998cb6611c266b0',\n    abi: [{ constant: true, inputs: [{ name: '', type: 'bytes32' }], name: 'topics', outputs: [{ name: '', type: 'address' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: false, inputs: [{ name: '_oracle', type: 'address' }, { name: '_name', type: 'bytes32[10]' }, { name: '_resultNames', type: 'bytes32[10]' }, { name: '_bettingEndBlock', type: 'uint256' }, { name: '_resultSettingEndBlock', type: 'uint256' }], name: 'createTopic', outputs: [{ name: 'topicEvent', type: 'address' }], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [{ name: '_name', type: 'bytes32[10]' }, { name: '_resultNames', type: 'bytes32[10]' }, { name: '_bettingEndBlock', type: 'uint256' }, { name: '_resultSettingEndBlock', type: 'uint256' }], name: 'doesTopicExist', outputs: [{ name: '', type: 'bool' }], payable: false, stateMutability: 'view', type: 'function' }, { inputs: [{ name: '_addressManager', type: 'address' }], payable: false, stateMutability: 'nonpayable', type: 'constructor' }, { anonymous: false, inputs: [{ indexed: true, name: '_topicAddress', type: 'address' }, { indexed: true, name: '_creator', type: 'address' }, { indexed: true, name: '_oracle', type: 'address' }, { indexed: false, name: '_name', type: 'bytes32[10]' }, { indexed: false, name: '_resultNames', type: 'bytes32[10]' }, { indexed: false, name: '_bettingEndBlock', type: 'uint256' }, { indexed: false, name: '_resultSettingEndBlock', type: 'uint256' }], name: 'TopicCreated', type: 'event' }],\n  },\n\n  TopicEvent: {\n    abi: [{ constant: false, inputs: [{ name: '_resultIndex', type: 'uint8' }, { name: '_sender', type: 'address' }, { name: '_amount', type: 'uint256' }], name: 'voteFromOracle', outputs: [{ name: '', type: 'bool' }], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [], name: 'totalBotValue', outputs: [{ name: '', type: 'uint256' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [{ name: '_oracleIndex', type: 'uint8' }], name: 'getOracle', outputs: [{ name: '', type: 'address' }, { name: '', type: 'bool' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [{ name: '', type: 'address' }], name: 'didWithdraw', outputs: [{ name: '', type: 'bool' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'resultSet', outputs: [{ name: '', type: 'bool' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'status', outputs: [{ name: '', type: 'uint8' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'getFinalResult', outputs: [{ name: '', type: 'uint8' }, { name: '', type: 'string' }, { name: '', type: 'bool' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [{ name: '', type: 'uint256' }], name: 'resultNames', outputs: [{ name: '', type: 'bytes32' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [{ name: '', type: 'uint256' }], name: 'oracles', outputs: [{ name: 'didSetResult', type: 'bool' }, { name: 'oracleAddress', type: 'address' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: false, inputs: [], name: 'finalizeResult', outputs: [{ name: '', type: 'bool' }], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: false, inputs: [{ name: '_oracle', type: 'address' }, { name: '_resultIndex', type: 'uint8' }, { name: '_consensusThreshold', type: 'uint256' }], name: 'centralizedOracleSetResult', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [], name: 'totalQtumValue', outputs: [{ name: '', type: 'uint256' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: false, inputs: [{ name: '_consensusThreshold', type: 'uint256' }], name: 'invalidateOracle', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [], name: 'getBetBalances', outputs: [{ name: '', type: 'uint256[10]' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'owner', outputs: [{ name: '', type: 'address' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'calculateQtumContributorWinnings', outputs: [{ name: '', type: 'uint256' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'getVoteBalances', outputs: [{ name: '', type: 'uint256[10]' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'getTotalVotes', outputs: [{ name: '', type: 'uint256[10]' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: false, inputs: [{ name: '_better', type: 'address' }, { name: '_resultIndex', type: 'uint8' }], name: 'bet', outputs: [], payable: true, stateMutability: 'payable', type: 'function' }, { constant: false, inputs: [{ name: '_resultIndex', type: 'uint8' }, { name: '_currentConsensusThreshold', type: 'uint256' }], name: 'votingOracleSetResult', outputs: [{ name: '', type: 'bool' }], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [], name: 'getTotalBets', outputs: [{ name: '', type: 'uint256[10]' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'getEventName', outputs: [{ name: '', type: 'string' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'invalidResultIndex', outputs: [{ name: '', type: 'uint8' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: true, inputs: [], name: 'numOfResults', outputs: [{ name: '', type: 'uint8' }], payable: false, stateMutability: 'view', type: 'function' }, { constant: false, inputs: [], name: 'withdrawWinnings', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: false, inputs: [{ name: '_newOwner', type: 'address' }], name: 'transferOwnership', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [], name: 'calculateBotContributorWinnings', outputs: [{ name: '', type: 'uint256' }], payable: false, stateMutability: 'view', type: 'function' }, { inputs: [{ name: '_owner', type: 'address' }, { name: '_centralizedOracle', type: 'address' }, { name: '_name', type: 'bytes32[10]' }, { name: '_resultNames', type: 'bytes32[10]' }, { name: '_bettingEndBlock', type: 'uint256' }, { name: '_resultSettingEndBlock', type: 'uint256' }, { name: '_addressManager', type: 'address' }], payable: false, stateMutability: 'nonpayable', type: 'constructor' }, { payable: true, stateMutability: 'payable', type: 'fallback' }, { anonymous: false, inputs: [{ indexed: true, name: '_eventAddress', type: 'address' }, { indexed: false, name: '_finalResultIndex', type: 'uint8' }], name: 'FinalResultSet', type: 'event' }, { anonymous: false, inputs: [{ indexed: true, name: '_winner', type: 'address' }, { indexed: false, name: '_htmlcoinTokenWon', type: 'uint256' }, { indexed: false, name: '_botTokenWon', type: 'uint256' }], name: 'WinningsWithdrawn', type: 'event' }, { anonymous: false, inputs: [{ indexed: true, name: '_previousOwner', type: 'address' }, { indexed: true, name: '_newOwner', type: 'address' }], name: 'OwnershipTransferred', type: 'event' }],\n  },\n};\n```\n\nUsage:\n```\nconst ContractMetadata = require('./contract_metadata');\n\nasync function(args) {\n  let {\n    fromBlock, // number\n    toBlock, // number\n    addresses, // string array\n    topics // string array\n  } = args;\n\n  if (addresses === undefined) {\n    addresses = [];\n  }\n  if (topics === undefined) {\n    topics = [];\n  }\n\n  // removeHexPrefix = true removes the '0x' hex prefix from all hex values\n  return await web3-tools.searchLogs(fromBlock, toBlock, addresses, topics, contractMetadata, true);\n}\n```\n\n## Contract.js\nInstantiate a new instance of `Contract`: \n```\nconst { web3-tools } = require('web3-tools');\n\nconst web3-tools = new web3-tools('http://htmlcoin:htmlcoin@localhost:14889');\n\n// contractAddress = The address of your contract deployed on the blockchain\nconst contractAddress = 'f7b958eac2bdaca0f225b86d162f263441d23c19';\n\n// contractAbi = The ABI of the contract\nconst contractAbi = [{\"constant\":false,\"inputs\":[{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_lastResultIndex\",\"type\":\"uint8\"},{\"name\":\"_arbitrationEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"createDecentralizedOracle\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_lastResultIndex\",\"type\":\"uint8\"},{\"name\":\"_arbitrationEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"doesDecentralizedOracleExist\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_oracle\",\"type\":\"address\"},{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_bettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_resultSettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"createCentralizedOracle\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_oracle\",\"type\":\"address\"},{\"name\":\"_eventAddress\",\"type\":\"address\"},{\"name\":\"_eventName\",\"type\":\"bytes32[10]\"},{\"name\":\"_eventResultNames\",\"type\":\"bytes32[10]\"},{\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"name\":\"_bettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_resultSettingEndBlock\",\"type\":\"uint256\"},{\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"doesCentralizedOracleExist\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"oracles\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_addressManager\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_contractAddress\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_oracle\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_eventAddress\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_name\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_resultNames\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"_bettingEndBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_resultSettingEndBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"CentralizedOracleCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_contractAddress\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_eventAddress\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_name\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_resultNames\",\"type\":\"bytes32[10]\"},{\"indexed\":false,\"name\":\"_numOfResults\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"_lastResultIndex\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"_arbitrationEndBlock\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_consensusThreshold\",\"type\":\"uint256\"}],\"name\":\"DecentralizedOracleCreated\",\"type\":\"event\"}];\n\n// Create a Contract instance from the web3-tools instance\nconst contract = web3-tools.Contract(contractAddress, contractAbi);\n```\n\n### call(methodName, params)\nExecutes a `callcontract`\n```\n// callcontract on a method named 'bettingEndBlock'\nasync function exampleCall(args) {\n  const {\n    senderAddress, // address\n  } = args;\n\n  return await contract.call('bettingEndBlock', {\n    methodArgs: [],\n    senderAddress: senderAddress,\n  });\n}\n```\n\n### send(methodName, params)\nExecutes a `sendtocontract`\n```\n// sendtocontract on a method named 'setResult'\nasync function exampleSend(args) {\n  const {\n    resultIndex, // number\n    senderAddress, // address\n  } = args;\n\n  return await contract.send('setResult', {\n    methodArgs: [resultIndex],\n    gasLimit: 1000000, // setting the gas limit to 1 million\n    senderAddress: senderAddress,\n  });\n}\n```\n\n## Encoder\n`Encoder` static functions are exposed in web3-tools instances.\n```\nconst { web3-tools } = require('web3-tools');\n\nconst web3-tools = new web3-tools('http://htmlcoin:htmlcoin@localhost:14889');\nweb3-tools.encoder.objToHash(abiObj, isFunction);\nweb3-tools.encoder.addressToHex(address);\nweb3-tools.encoder.boolToHex(value);\nweb3-tools.encoder.intToHex(num);\nweb3-tools.encoder.uintToHex(num);\nweb3-tools.encoder.stringToHex(string, maxCharLen);\nweb3-tools.encoder.stringArrayToHex(strArray, numOfItems);\nweb3-tools.encoder.padHexString(hexStr);\nweb3-tools.encoder.constructData(abi, methodName, args);\n```\n\n## Decoder\n`Decoder` static functions are exposed in web3-tools instances.\n```\nconst { web3-tools } = require('web3-tools');\n\nconst web3-tools = new web3-tools('http://htmlcoin:htmlcoin@localhost:14889');\nweb3-tools.decoder.toHtmlcoinAddress(hexAddress, isMainnet);\nweb3-tools.decoder.removeHexPrefix(value);\nweb3-tools.decoder.decodeSearchLog(rawOutput, contractMetadata, removeHexPrefix);\nweb3-tools.decoder.decodeCall(rawOutput, contractABI, methodName, removeHexPrefix);\n```\n\n## Utils\n`Utils` static functions are exposed in web3-tools instances.\n```\nconst { web3-tools } = require('web3-tools');\n\nconst web3-tools = new web3-tools('http://htmlcoin:htmlcoin@localhost:14889');\nweb3-tools.utils.paramsCheck(methodName, params, required, validators);\nweb3-tools.utils.appendHexPrefix(value);\nweb3-tools.utils.trimHexPrefix(str);\nweb3-tools.utils.chunkString(str, length);\nweb3-tools.utils.toUtf8(hex);\nweb3-tools.utils.fromUtf8(str);\nweb3-tools.utils.isJson(str);\nweb3-tools.utils.isHtmlcoinAddress(address);\n```\n\n## Running Tests\nYou need to create a `.env` file in the root folder with the following variables in the following formats. Change it to how your environment is setup.\n```\nHTMLCOIN_RPC_ADDRESS='http://htmlcoin:htmlcoin@localhost:14889'\nSENDER_ADDRESS='hMZK8FNPRm54jvTLAGEs1biTCgyCkcsmna'\nWALLET_PASSPHRASE='htmlcoin'\n```\n","readmeFilename":"README.md"}