{"id":23114777,"url":"https://github.com/brickpop/eth-tx","last_synced_at":"2026-05-16T18:05:27.827Z","repository":{"id":57230803,"uuid":"103300622","full_name":"brickpop/eth-tx","owner":"brickpop","description":"JS library to ease the compilation, deployment and interaction with Ethereum Smart Contracts","archived":false,"fork":false,"pushed_at":"2018-10-17T00:42:35.000Z","size":476,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T00:51:34.169Z","etag":null,"topics":["eth","ethereum","rpc","transaction","web3","web3js"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brickpop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-12T17:22:21.000Z","updated_at":"2021-11-15T07:55:44.000Z","dependencies_parsed_at":"2022-08-29T07:00:40.429Z","dependency_job_id":null,"html_url":"https://github.com/brickpop/eth-tx","commit_stats":null,"previous_names":["ledfusion/eth-tx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickpop%2Feth-tx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickpop%2Feth-tx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickpop%2Feth-tx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickpop%2Feth-tx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brickpop","download_url":"https://codeload.github.com/brickpop/eth-tx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247103297,"owners_count":20884023,"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":["eth","ethereum","rpc","transaction","web3","web3js"],"created_at":"2024-12-17T03:34:53.683Z","updated_at":"2026-05-16T18:05:27.798Z","avatar_url":"https://github.com/brickpop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Ethereum TX\n---\n\nEthereum TX is a Javascript library inspired on the work of Jordy Baylina ([runethtx](https://github.com/jbaylina/runethtx) and [ethconnector](https://github.com/jbaylina/ethconnector)).\n\n* It provides a unified way to **compile**, **deploy**, **query** and **send transactions** to Ethereum Smart Contracts with ease.\n* It also allows to perform simple operations in a simple way\n* It abstracts the usage of the web3 component (you can provide your own, too)\n\n# Environment\n\n**NOTE**: This version is only targeted for NodeJS usage.\n\nYou may be able to import it using Webpack, but the compiler functions will not work, and ES6 features might need transpiling.\n\n# Installation\n\n```sh\n$ npm install eth-tx\n```\n\nOnce the package is ready, import it in your app:\n\n```javascript\nconst ethTx = require(\"eth-tx\");\n```\n\n# Usage\n\n## Connection\n\n```javascript\nconst { connect, useConnection } = ethTx;\n```\n\nTo simply connect to `localhost:8545`, you can use:\n\n```javascript\nconnect()\n\t.then(() =\u003e console.log(\"Success\"))\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\nYou can specify a custom URL like so:\n\n```javascript\nconnect(\"http://localhost:8545\")\n\t.then(() =\u003e console.log(\"Success\"))\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\nOr you can reuse an already existing web3 instance:\n\n```javascript\nuseConnection(web3)\n\t.then(() =\u003e console.log(\"Success\"))\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\nAt any time, you can check if a connection is already established:\n\n```javascript\nconst { isConnected } = ethTx;\n\nisConnected(); // returns true or false\n```\n\nAnd you can also subscribe to connection status changes. You will receive a status object with the properties `{ connected, network, accounts }`.\n\n```javascript\nconst { onConnectionChanged } = ethTx;\n\nonConnectionChanged(status =\u003e {\n\tif(!status.connected) {\n\t\tconsole.log(\"Web3 support is not available\");\n\t}\n\telse if(status.accounts \u0026\u0026 status.accounts.length) {\n\t\tconsole.log(`Connected to ${status.network} =\u003e ${status.accounts.join()}`);\n\t}\n\telse {\n\t\tconsole.log(`The ${status.network} network is currently locked`);\n\t}\n});\n```\n\nSome of the operations described below may require that a connection is already established.\n\n## Compiling\n\n```javascript\nconst { compileTo, compileBundled, bundleContractFile } = ethTx;\n```\n\n### In-memory\nIn NodeJS you can use:\n\n```javascript\nbundleContractFile(entrySrcFile)\n\t.then(smartContractSourceBundled =\u003e {\n\t\treturn compileBundled(smartContractSourceBundled)\n\t})\n\t.then(contracts =\u003e {\n\t\t// your code here\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n### File system\nTo compile a smart contract from the local file system (NodeJS only):\n\n```javascript\nconst fs = require('fs');\nconst path = require('path');\n\nconst source = path.join(__dirname, \"contract-main.sol\");\nconst destination = path.join(__dirname, \"..\", \"build\", \"contracts.js\");\n\nif (!fs.existsSync(path.dirname(destination))) {\n  fs.mkdirSync(path.dirname(destination));\n}\n\ncompileTo(source, destination, {})\n\t.then(() =\u003e { /* ... */})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n## Working with contracts\n\nOnce a contract is compiled, you can wrap it into a class/object using the function `wrapContract`.\n\n```javascript\nconst { wrapContract } = ethTx;\n```\n\nThis function generates a customized Javascript class, containing the methods and operations of the contract.\n\n### Deploying a contract\n\nOnce a contract is compiled, get its Application Binary Interface (ABI) and its Byte Code:\n\n```javascript\nconst abi = [...];\nconst byteCode = \"0x12345...\";\n\nconst MyContract = wrapContract(abi, byteCode);\n\nMyContract.new(\"parameter-1\", \"parameter-2\")\n\t.then(myContractInstance =\u003e {\n\t\tconsole.log(\"Deployed on\", myContractInstance.$address);\n\n\t\t// ...\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\nThe static method `new(...)` returns a promise that resolves with an instance of the newly deployed contract.\n\n### Attaching to an already deployed contract\n\nTo interact with a contract already deployed to the BlockChain, use the constructor with the address:\n\n```javascript\nconst abi = [...];\nconst byteCode = \"0x12345...\";\nconst address = \"0x1234567890...\";\n\nconst MyContract = wrapContract(abi, byteCode);\n\nconst myContractInstance = new MyContract(address);\n\n```\n\n### Interacting with a contract instance\n\n#### Sending a transaction to the contract\n\nPass the parameters as show below. Invoking the `.send()` method will send the transaction to the net and may change the state of the contract.\n\n```javascript\nconst options = {};\nmyContractInstance.setHash(\"param-1\", \"param-2\").send(options)\n\t.then(transaction =\u003e {\n\t\tconsole.log(\"Transaction\", transaction);\n\n\t\t// ...\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n#### Calling a read-only function\n\nPass the parameters as show below. Invoking the `.call()` method will execute the function of the contract and resolve to any value that might be returned.\n\nThis invocation will not change the state, as no transaction will be sent to the blockchain.\n\n```javascript\nconst options = {};\nmyContractInstance.getHash(\"param-1\").call(options)\n\t.then(value =\u003e {\n\t\tconsole.log(\"Resulting value\", value);\n\n\t\t// ...\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n#### Retrieving public variables\n\nThe same scenario applies to the public variables of a contract instance.\n\n```javascript\nmyContractInstance.totalAmount().call()\n\t.then(value =\u003e {\n\t\tconsole.log(\"totalAmount =\", value);\n\n\t\t// ...\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n#### Estimate the gas cost\n\nPass the parameters as show below. Invoking the `.estimateGas()` method will evaluate the code and resolve the promise to the amount of gas expected to be spent on a successful transaction.\n\n```javascript\nconst options = {};\nmyContractInstance.setHash(\"param-1\", \"param-2\").estimateGas(options)\n\t.then(gas =\u003e {\n\t\tconsole.log(\"Estimated cost\", gas);\n\n\t\t// ...\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n#### Invoke the fallback function\n\nSimply send a transaction to the contract's address\n\n```javascript\nconst params = {\n\tto: myContractInstance.$address,\n\tvalue: 10 // wei\n};\n\nethTx.sendTransaction(params)\n\t.then(receipt =\u003e {\n\t\tconsole.log(\"Receipt:\", receipt);\n\n\t\t// ...\n\t})\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n## Working with simple transactions\n\nTransactions can simply be a matter or transfering funds to another account.\n\n```javascript\nvar accounts;\nconst { getAccounts, sendTransaction } = ethTx;\n\ngetAccounts()\n\t.then(acc =\u003e { accounts = acc; })\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\nTo send ether to another account, we can simply:\n\n```javascript\nconst amount = ethTx.getCurrentWeb3().utils.toWei(\"0.01\", \"ether\");\n\nconst params = {\n\t// from: \"0x123456...\",  // by default will be accounts[0]\n\tto: accounts[1],\n\tvalue: amount,\n\t// data: \"0x12345...\"  // optional bytecode\n};\n\nsendTransaction(params)\n\t.then(result =\u003e console.log(\"Result\", result))\n\t.catch(err =\u003e console.log(\"Error\", err));\n```\n\n## Utilities\n\n```javascript\nconst { getBalance, getBlock, getNetwork } = ethTx;\n```\n\nThese two functions are simply a wrapper of their corresponding method in `web3`. They return a `Promise` resolving to the appropriate value.\n\n## Examples\n\nCheck out the file `example/index.js` for a NodeJS script.\n\n```sh\n$ node example\n```\n\n## About\n\nBy Jordi Moraleda\n\n\u003c!-- You can buy me a coffe ☕️ [0x093d4d1e3f8db7cfb06d3b638fbf44156e12b3dc](https://etherscan.io/address/0x093d4d1e3f8db7cfb06d3b638fbf44156e12b3dc#)--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrickpop%2Feth-tx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrickpop%2Feth-tx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrickpop%2Feth-tx/lists"}