{"id":13746580,"url":"https://github.com/cowprotocol/ethcontract-rs","last_synced_at":"2025-05-16T05:04:12.723Z","repository":{"id":35541569,"uuid":"215829151","full_name":"cowprotocol/ethcontract-rs","owner":"cowprotocol","description":"Generate type-safe bindings for interacting with Ethereum contracts.","archived":false,"fork":false,"pushed_at":"2025-01-06T18:17:48.000Z","size":2567,"stargazers_count":314,"open_issues_count":67,"forks_count":45,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-08T05:46:26.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cowprotocol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-17T15:44:20.000Z","updated_at":"2025-05-01T02:15:28.000Z","dependencies_parsed_at":"2024-06-19T10:01:16.504Z","dependency_job_id":"78ff4f82-a0c7-447b-a015-56b4aac0b0d4","html_url":"https://github.com/cowprotocol/ethcontract-rs","commit_stats":null,"previous_names":["cowprotocol/ethcontract-rs","gnosis/ethcontract-rs"],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowprotocol%2Fethcontract-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowprotocol%2Fethcontract-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowprotocol%2Fethcontract-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowprotocol%2Fethcontract-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cowprotocol","download_url":"https://codeload.github.com/cowprotocol/ethcontract-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253009843,"owners_count":21839713,"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-03T06:00:55.977Z","updated_at":"2025-05-16T05:04:12.704Z","avatar_url":"https://github.com/cowprotocol.png","language":"Rust","funding_links":[],"categories":["Rust","Decentralized Finance (DeFi)"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/gnosis/ethcontract-rs.svg?branch=main)](https://travis-ci.org/gnosis/ethcontract-rs)\n[![Crates.io](https://img.shields.io/crates/v/ethcontract.svg)](https://crates.io/crates/ethcontract)\n[![Docs.rs](https://docs.rs/ethcontract/badge.svg)](https://docs.rs/ethcontract)\n[![Rustc Version](https://img.shields.io/badge/rustc-1.70+-lightgray.svg)](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html)\n\n# `ethcontract-rs`\n\nCrate used for generating code for Ethereum smart contracts. It provides a\nfunction procedural macro that generates safe bindings for contract interaction\nbased on the contract ABI.\n\n## Getting Started\n\nAdd a dependency to the `ethcontract` crate in your `Cargo.toml`:\n\n```toml\n[dependencies]\nethcontract = \"...\"\n```\n\nThen generate a struct for interacting with the smart contract with a type-safe\nAPI:\n\n```rust\nethcontract::contract!(\"path/to/truffle/build/contract/Contract.json\");\n```\n\nThis will generate a new struct `ContractName` with contract generated methods\nfor interacting with contract functions in a type-safe way.\n\n### Minimum Supported Rust Version\n\nThe minimum supported Rust version is 1.64.0\n\n## Generator API\n\nAs an alternative to the procedural macro, a generator API is provided for\ngenerating contract bindings from `build.rs` scripts. More information can be\nfound in the `ethcontract-generate` [README](ethcontract-generate/README.md).\n\n## Running the Examples\n\nIn order to run local examples you will additionally need:\n- NodeJS LTS\n- Yarn\n\nFor all examples, the smart contracts must first be built:\n\n```sh\ncd examples/truffle\nyarn \u0026\u0026 yarn build\n```\n\n### Truffle Examples\n\nTruffle examples rely on the local truffle development server. In a separate\nterminal run:\n\n```sh\ncd examples/truffle\nyarn start\n```\n\n#### ABI:\n\nThe `abi` example deploys a simple contract and performs various `eth_call`s\nto illustrate how Solidity types are mapped to Rust types by `ethcontract`.\n\n```sh\ncargo run --example abi\n```\n\n#### Async/Await:\n\nThe `async` example deploys an ERC20 token and interacts with the contract\nwith various accounts.\n\n```sh\ncargo run --example async\n```\n\n#### Manual Deployments:\n\nThe `deployments` example illustrates how the `deployments` parameter can be\nspecified when generating a contract with the `ethcontract::contract!` macro.\nThis can be useful for specifying addresses in testing environments that are\ndeterministic but either not included, or inaccurate in the artifact's\n`networks` property (when for example the contract is developed upstream, but\na separate testnet deployment wants to be used).\n\n```sh\ncargo run --example deployments\n```\n\n#### Events:\n\nThe `events` example illustrates how to listen to logs emitted by smart\ncontract events.\n\n```sh\ncargo run --example events\n```\n\n#### Generator API (with `build.rs` script):\n\nThe `generator` example (actually a separate crate to be able to have a build\nscript) demonstrates how the generator API can be used for creating type-safe\nbindings to a smart contract with a `build.rs` build script.\n\n```sh\ncargo run --package examples-generate\n```\n\n#### Contract Linking:\n\nThe `linked` example deploys a library and a contract that links to it then\nmakes a method call.\n\n```sh\ncargo run --example linked\n```\n\n#### Deployed Bytecode\n\nThe `bytecode` example deploys a contract and verifies its bytecode matches the\nexpected value from the contract artifact.\n\n```sh\ncargo run --example bytecode\n```\n\n### Rinkeby Example\n\nThere is a provided example that runs with Rinkeby and Infura. Running this\nexample is a little more involved to run because it requires a private key with\nfunds on Rinkeby (for gas) as well as an Infura project ID in order to connect\nto a node. Parameters are provided to the Rinkeby example by environment\nvariables:\n\n```sh\nexport PK=\"private key\"\nexport INFURA_PROJECT_ID=\"Infura project ID\"\ncargo run --example rinkeby\n```\n\n### Mainnet Examples\n\n#### Sources:\n\nThis example generates contract bindings from online sources:\n- A verified contract on Etherscan\n- An npmjs contract\n\nIt also queries some contract state with Infura. Running this example requires\nan Infura project ID in order to connect to a node. Parameters are provided to\nthe example by environment variables:\n\n```sh\nexport INFURA_PROJECT_ID=\"Infura project ID\"\ncargo run --example sources\n```\n\n#### Past Events:\n\nThis example retrieves the entire event history of token OWL contract and prints\nthe total number of events since deployment.\n\nNote the special handling of the `tokenOWLProxy` contract and how it is cast into\na `tokenOWL` instance using Contract's `with_deployment_info` feature.\n\n```sh\nexport INFURA_PROJECT_ID=\"Infura project ID\"\ncargo run --example past_events\n```\n\n## Sample Contracts Documentation\n\nYou can view example generated contract documentation by fist building the\ncontracts and then generating documentation for the crate:\n\n```sh\n(cd examples/truffle; yarn \u0026\u0026 yarn build)\ncargo doc --package examples-documentation --no-deps --open\n```\n\nThis will open a browser at the documentation root.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcowprotocol%2Fethcontract-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcowprotocol%2Fethcontract-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcowprotocol%2Fethcontract-rs/lists"}