{"id":13600875,"url":"https://github.com/uzyn/web3-loader","last_synced_at":"2025-08-24T22:24:22.454Z","repository":{"id":143927915,"uuid":"57023506","full_name":"uzyn/web3-loader","owner":"uzyn","description":"Ethereum web3.js module for Webpack. Deploys and returns instantiated contract.","archived":false,"fork":false,"pushed_at":"2016-11-10T02:56:48.000Z","size":36,"stargazers_count":28,"open_issues_count":5,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-31T19:23:43.344Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/web3-loader","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uzyn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-04-25T08:09:26.000Z","updated_at":"2024-05-26T10:43:42.000Z","dependencies_parsed_at":"2024-01-16T23:26:12.569Z","dependency_job_id":"a2632dc0-22fc-493a-95ad-c429d94a4a46","html_url":"https://github.com/uzyn/web3-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzyn%2Fweb3-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzyn%2Fweb3-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzyn%2Fweb3-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzyn%2Fweb3-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uzyn","download_url":"https://codeload.github.com/uzyn/web3-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223581935,"owners_count":17168655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T18:00:50.313Z","updated_at":"2024-11-07T20:06:24.177Z","avatar_url":"https://github.com/uzyn.png","language":"JavaScript","funding_links":[],"categories":["ETH"],"sub_categories":["Libraries"],"readme":"# web3 loader for webpack\n\nDeploys Ethereum VM bytecode and returns ready-to-use JavaScript instance of the deployed smart contract(s). Also returns initialized web3 object from [Web3 object](https://github.com/ethereum/wiki/wiki/JavaScript-API) for easy usage.\n\nIdeally to be used with [solc-loader](https://github.com/uzyn/solc-loader) for solidity compilation and bytecode generation.\n\nA web3 provider is required when running `web3-loader`. [testrpc](https://github.com/ethereumjs/testrpc) is handy during development, while [geth](https://github.com/ethereum/go-ethereum) would be useful to test in actual Ethereum environment where blocks are not mined immediately after every actions.\n\n##### Sample code\n\nSample dapp or starter kit can be found at [uzyn/ethereum-webpack-example-dapp](https://github.com/uzyn/ethereum-webpack-example-dapp).\n\n## Installation\n\n```bash\nnpm install web3-loader --save-dev\n```\n\n## Usage\n\nThis loader is ideally to be used after `solc-loader` on Solidity smart contract code (`.sol`).\n\n### Example webpack config\n\nAt your project's `webpack.config.js`:\n\n```js\nmodule.exports = {\n  module: {\n    loaders: [\n      {\n        test: /\\.sol$/,\n        loaders: ['web3', 'solc']\n    ]\n  }\n}\n```\n\n### Usage in your project\n\nUsing [Ethereum's The Coin](https://www.ethereum.org/token) as an example:\n\n```js\nimport { MyToken } from './contract/MyToken.sol';\n\n// MyToken is now available as a ready-to-use contract instance\nconst symbol = MyToken.symbol();\nMyToken.transfer('0x............', 1);\n```\n\nYou can also interact with the ininitialized web3 instance without having to import and initialize web3 in your code.\n\n```js\nimport { MyToken, web3 } from './contract/MyToken.sol';\n\nlet currentBlock = web3.eth.blockNumber;\n```\n### Solidity Contract Dependency Injection\n\nThis loader is able to automatically inject address of deployed contract if your contracts depends on it.\nTo use dependency injection you will need:\n - Contracts.sol - a central file which you will `require` in your js\n - `inject_` constructor variables\n\nConsider such example:\n```\n//Manager.sol\ncontract Manager {\n  //Some state + complex stuff that is accessed by other contracts\n}\n\n//SomeContract.sol\nimport 'Manager.sol';\n\ncontract SomeContract1 {\n\n  address manager;\n\n  function SomeContract(inject_Manager) {\n    manager = inject_Manager;\n  }\n\n  function doSmth() {\n    Manager(manager).someMethod();\n  }\n}\n\n//Contracts.sol will contain just 'import' statements\nimport 'SomeContract1';\n```\n\nIn JS code:\n```js\nvar contracts = require('Contracts.sol');\nvar SomeContract1 = contracts.SomeContract;\nvar Manager = contracts.Manager;\nvar web3 = contracts.web3;\n```\n\nIn `Contracts.sol` only root contracts can be specified. Loader automatically builds dependency\ngraph based on `import` statements and `inject_` constructor variables.\nRun `webpack -d` to see debug information on the order of deployment.\n\nIf your construct must accept other variables they should be placed before because loader just appends injected contract addresses to the end of `constructorParams` config variable.\n\n## Configuration\n\nConfiguration is _not needed_ for most common use cases.\n\n### Options\n\n1. `provider`\n    - Web3 provider\n    - Default: `http://localhost:8545`\n1. `from`\n    - Account to deploy contract from.\n    - Default: first account at your Web3 provider, ie. `web3.eth.accounts[0]`.\n1. `gasLimit`\n    - Maximum gas allowed for deploying of each contracts.\n    - Default: latest gasLimit of Ethereum, ie. `web3.eth.getBlock(web3.eth.defaultBlock).gasLimit`\n1. `constructorParams`\n    - Specify contract constructor parameters, if any.\n    - Parameters for a contract must be listed in an array form.\n    - Default: `{}` _(empty object)_\n    - See next section for example.\n1. `deployedContracts`\n    - If you would like to use existing deployed contracts, specify contract addresses for each contracts.\n    - If a contract is not found, it would be deployed at build.\n    - Default: `{}` _(empty object)_\n    - See next section for example.\n\n#### Config style\n\nRecommended especially for configuring of contract addresses.\n\n```js\n// webpack.config.js\nmodule.exports = {\n  web3Loader: {\n    // Web3\n    provider: 'http://localhost:8545',\n\n    // For deployment\n    from: '0xFfA57D3e88A24311565C9929F180739E43FBD0aA',\n    gasLimit: 100000,\n\n    // Specify contract constructor parameters, if any.\n    // constructorParams: {\n    //   ContractOne: [ 'param1_value', 'param2_value' ]\n    // }\n    constructorParams: {},\n\n    // To use deployed contracts instead of redeploying, include contract addresses in config\n    // deployedContracts: {\n    //   ContractOne: '0x...........',\n    //   ContractTwo: '0x...........',\n    // }\n    deployedContracts: {}\n  }\n}\n```\n\n#### Query style\n\nQuery style is also supported but can be tricky for `constructorParams` and `deployedContracts`.\n\n```js\nloaders: ['web3?gasLimit=50000\u0026provider=http://example.org:8545']\n```\n\n\n## License\nMIT · [U-Zyn Chua](http://uzyn.com) ([@uzyn](http://twitter.com/uzyn))\n\nTips: `0xFfA57D3e88A24311565C9929F180739E43FBD0aA`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzyn%2Fweb3-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuzyn%2Fweb3-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzyn%2Fweb3-loader/lists"}