{"id":19107492,"url":"https://github.com/smartcontractkit/truffle-starter-kit","last_synced_at":"2025-04-07T16:18:03.287Z","repository":{"id":39851801,"uuid":"243400508","full_name":"smartcontractkit/truffle-starter-kit","owner":"smartcontractkit","description":"An example smart contract utilizing Chainlink","archived":false,"fork":false,"pushed_at":"2023-02-08T20:59:34.000Z","size":936,"stargazers_count":268,"open_issues_count":2,"forks_count":100,"subscribers_count":87,"default_branch":"main","last_synced_at":"2025-03-31T14:11:15.449Z","etag":null,"topics":["chainlink","ethereum","javascript","truffle"],"latest_commit_sha":null,"homepage":"","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/smartcontractkit.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}},"created_at":"2020-02-27T01:08:01.000Z","updated_at":"2025-03-27T14:31:48.000Z","dependencies_parsed_at":"2022-07-06T02:31:11.489Z","dependency_job_id":"9c8a0637-b08a-4d76-b953-8afd88266e49","html_url":"https://github.com/smartcontractkit/truffle-starter-kit","commit_stats":null,"previous_names":[],"tags_count":2,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Ftruffle-starter-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Ftruffle-starter-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Ftruffle-starter-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Ftruffle-starter-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartcontractkit","download_url":"https://codeload.github.com/smartcontractkit/truffle-starter-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247685628,"owners_count":20979085,"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":["chainlink","ethereum","javascript","truffle"],"created_at":"2024-11-09T04:12:47.632Z","updated_at":"2025-04-07T16:18:03.269Z","avatar_url":"https://github.com/smartcontractkit.png","language":"JavaScript","readme":"\u003cbr/\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://chain.link\" target=\"_blank\"\u003e\n\u003cimg src=\"./box-img-lg.png\" width=\"225\" alt=\"Chainlink Truffle logo\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr/\u003e\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/smartcontractkit/truffle-starter-kit)\n\n- [Chainlink Truffle Starter Kit](#chainlink-truffle-starter-kit)\n- [Getting Started](#getting-started)\n- [It's recommended that you've gone through the Truffle getting started documentation before proceeding here.](#its-recommended-that-youve-gone-through-the-truffle-getting-started-documentation-before-proceeding-here)\n  - [Requirements](#requirements)\n  - [Quickstart](#quickstart)\n- [Usage](#usage)\n  - [Deploying Contracts](#deploying-contracts)\n  - [Run a Local Network](#run-a-local-network)\n  - [Using a Testnet or Live Network (like Mainnet or Polygon)](#using-a-testnet-or-live-network-like-mainnet-or-polygon)\n    - [Sepolia Ethereum Testnet Setup](#sepolia-ethereum-testnet-setup)\n- [Test](#test)\n- [Interacting with Deployed Contracts](#interacting-with-deployed-contracts)\n  - [Chainlink Price Feeds](#chainlink-price-feeds)\n  - [Request \u0026 Receive Data](#request--receive-data)\n  - [VRF Get a random number](#vrf-get-a-random-number)\n  - [Keepers](#keepers)\n  - [Verify on Etherscan](#verify-on-etherscan)\n- [Contributing](#contributing)\n- [Thank You!](#thank-you)\n  - [Resources](#resources)\n\n# Chainlink Truffle Starter Kit\n Implementation of the following 4 Chainlink features using the [Truffle](https://trufflesuite.com/) development environment:\n - [Chainlink Price Feeds](https://docs.chain.link/docs/using-chainlink-reference-contracts)\n - [Chainlink VRF](https://docs.chain.link/docs/chainlink-vrf)\n - [Chainlink Keepers](https://docs.chain.link/docs/chainlink-keepers/introduction/)\n - [Request \u0026 Receive data](https://docs.chain.link/docs/request-and-receive-data)\n\n# Getting Started \n\nIt's recommended that you've gone through the [Truffle getting started documentation](https://trufflesuite.com/docs/truffle/getting-started/compiling-contracts/) before proceeding here. \n=======\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/smartcontractkit/truffle-starter-kit)\n\n\n## Requirements\n\n- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)\n  - You'll know you did it right if you can run `git --version` and you see a response like `git version x.x.x`\n- [Nodejs](https://nodejs.org/en/)\n  - You'll know you've installed nodejs right if you can run:\n    - `node --version`and get an ouput like: `vx.x.x`\n- [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/) instead of `npm`\n  - You'll know you've installed yarn right if you can run:\n    - `yarn --version` And get an output like: `x.x.x`\n    - You might need to install it with npm\n\n\u003e If you're familiar with `npx` and `npm` instead of `yarn`, you can use `npx` for execution and `npm` for installing dependencies. \n\n## Quickstart\n\n1. Clone and install dependencies\n\nAfter installing all the requirements, run the following:\n\n```bash\ngit clone https://github.com/smartcontractkit/truffle-starter-kit/\ncd truffle-starter-kit\n```\nThen:\n```\nyarn\n```\n\nor\n```\nnpm i\n```\n\n2. You can now do stuff!\n\nRun `truffle test`\n\nThis will run your JavaScript, TypeScript, and Solidity tests underneath the `./test` folder. If the `development` network is not specified in your `truffle-config`, `truffle test` will automatically bring up and tear down a local network on `localhost:8545`.\n\n# Usage\n\nIf you run `truffle --help` you'll get an output of all the tasks you can run.\n\n## Deploying Contracts\n\nIn your `truffle-config.js` you'll see section like:\n\n```\n  networks: {\n```\n\nThis section of the file is where you define which networks you want to interact with. You can read more about that whole file in the [Truffle documentation.](https://trufflesuite.com//config/). To deploy a contract, you would call:\n\n```\ntruffle migrate --network \u003cNETWORK\u003e\n```\n\nThis will deploy your contracts to the network you specify. If you do not specify `network`, by default `truffle migrate` will deploy to the `development` network if it is defined in your `truffle-config`.\n\nIf you'd like to interact with your deployed contracts, skip down to [Interacting with Deployed Contracts](#interacting-with-deployed-contracts).\n\n## Run a Local Network\n\nOne of the best ways to test and interact with smart contracts is with a local network. To start a local network with all your contracts in it, run the following:\n\n```\nganache -d\n```\n\nThis will start `ganache`, a local blockchain with private keys, pre-funded wallets, and an endpoint to potentially add to an EVM wallet. `-d` specifies a deterministic wallet. You can see all other ways you can configure Ganache [here](https://github.com/trufflesuite/ganache).\n\nIn our `truffle-config`, we've defined the local `ganache` network. To migrate, simply call:\n\n```\ntruffle migrate --network ganache\n```\n\n## Using a Testnet or Live Network (like Mainnet or Polygon)\n\nTo interact with a live or test network, you will need ETH and LINK token by following these steps:\n\n1. Get some Sepolia Testnet ETH and LINK \n\nHead over to the [Chainlink faucets](https://faucets.chain.link/) and get some ETH and LINK. Please follow [the chainlink documentation](https://docs.chain.link/docs/acquire-link/) if unfamiliar. \n\n4. Create VRF V2 subscription\n\nHead over to [VRF Subscription Page](https://vrf.chain.link/sepolia) and create the new subscription. Save your subscription ID and place it in your `helper-truffle-config.js` under `subId`.\n\n### Truffle Dashboard\n\nThis is our recommended way of deploying your contracts. With [Truffle dashboard](https://trufflesuite.com/docs/truffle/getting-started/using-the-truffle-dashboard/), you can deploy contracts and sign transactions through MetaMask - so you never exposing your private key! To do so, run:\n\n`truffle dashboard`\n\nThis should bring up the dashboard on `localhost:24012`, where you can connect your wallet to the network of your choice. Note that if you want to deploy to a testnet or mainnet, you'll need ETH to pay the gas fees. Then, if you want to migrate your contracts, simply call:\n\n`truffle migrate --network dashboard`\n\nYou should then see prompts to sign the transactions on the dashboard view. Check out this video on how to use it with Truffle and HardHat [here](https://youtu.be/AnprU4z-q0k).\n\n### Environment configuration\n\nIn some cases, you might want your transactions to be automatically signed. In which case, you will need to provide your wallet's private key\n\n1. An RPC URL\n2. A private key\n3. ETH \u0026 LINK token (either testnet or real)\n\nLet's look at an example of setting these up using the Sepolia testnet. \n\n### Sepolia Ethereum Testnet Setup\n\nFirst, we will need to set environment variables. We can do so by setting them in our `.env` file (create it if it's not there). You can also read more about [environment variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html) from the linked twilio blog. You'll find a sample of what this file will look like in `.env.example`\n\n\u003e IMPORTANT: MAKE SURE YOU'D DONT EXPOSE THE KEYS YOU PUT IN THIS `.env` FILE. By that, I mean don't push them to a public repo, and please try to keep them keys you use in development not associated with any real funds. \n\n1. Set your `SEPOLIA_RPC_URL` [environment variable.](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html)\n\nYou can get one for free from [Infura](https://infura.io/), [Alchemy](https://www.alchemy.com/), or [Moralis](https://moralis.io/speedy-nodes/). This is your connection to the blockchain.\n\n2. Set your `PRIVATE_KEY` environment variable. \n\nThis is your private key from your wallet, ie [MetaMask](https://metamask.io/). This is needed for deploying contracts to public networks. \n\n![WARNING](https://via.placeholder.com/15/f03c15/000000?text=+) **WARNING** ![WARNING](https://via.placeholder.com/15/f03c15/000000?text=+)\n\nWhen developing, it's best practice to use a Metamask that isn't associated with any real money. A good way to do this is to use Truffle Dashboard. Alternatively, make a new browser profile (on Chrome, Brave, Firefox, etc) and install Metamask on that brower, and never send this wallet money.  \n\nDon't commit and push any changes to .env files that may contain sensitive information, such as a private key! If this information reaches a public GitHub repository, someone can use it to check if you have any Mainnet funds in that wallet address, and steal them!\n\n`.env` example:\n```\nSEPOLIA_RPC_URL='https://sepolia.infura.io/v3/asdfasdfasdfasdf'\nPRIVATE_KEY='abcdef'\n```\n`bash` example\n```\nexport SEPOLIA_RPC_URL='https://sepolia.infura.io/v3/asdfasdfasdfasdf'\nexport PRIVATE_KEY='abcdef'\n```\n\nFor other networks like mainnet and polygon, you can use different environment variables for your RPC URL and your private key. See the `truffle-config.js` to learn more. \n\nUncomment the `sepolia` network in your `truffle-config`. You should now be all setup! You can run any command and just pass the `--network sepolia` now!\n\nTo deploy all contracts:\n\n```\ntruffle migrate --network sepolia\n```\n\n# Test\n\nTests are located in the [test](./test/) directory, and are split between unit tests and staging/testnet tests. Unit tests should only be run on local environments, and staging tests should only run on live environments.\n\nTo run unit tests:\n\n```bash\ntruffle test\n```\n\n# Interacting with Deployed Contracts\n\nAfter deploying your contracts, the deployment output will give you the contract addresses as they are deployed. You can then use these contract addresses in conjunction with Truffle scripts to perform operations on each contract. Alternatively, if you want to interact with contracts on the fly, you can read about how to use `truffle console` or `truffle develop` [here](https://trufflesuite.com/docs/truffle/getting-started/using-truffle-develop-and-the-console/).\n\n## Chainlink Price Feeds\n\nThe Price Feeds consumer contract has one script, to read the latest price of a specified price feed contract. \n\nYou can deploy just the price feed consumer with:\n\n```bash\ntruffle migrate --f 3 --to 3 --network \u003cNETWORK\u003e\n```\n\nAfter deployment, run the following:\n\n```bash\ntruffle exec scripts/readPriceConsumer.js --network \u003cNETWORK\u003e\n```\n\n## Request \u0026 Receive Data\n\nThe API Consumer contract has one script, to request data from the API and wait for a response. \n\nYou can deploy just the API Consumer with:\n\n```\ntruffle migrate --f 4 --to 4 --network \u003cNETWORK\u003e\n```\n\nAfter deployment, run the following:\n\n```bash\nyarn truffle exec scripts/requestAndReadAPI.js --network \u003cNETWORK\u003e\n```\n\n## VRF Get a random number\n\nThe VRF Consumer contract has one script, to request a random number and wait for a response. \n\nYou can deploy just the VRF Consumer with:\n\n```\ntruffle deploy --f 5 --to 5 --network \u003cNETWORK\u003e\n```\n\nAfter deployment, you'll need to add your contract address to your subscription. Head over to [vrf.chain.link](https://vrf.chain.link/sepolia/new) and add your consumer. \n\nThen, run the following:\n\n```bash\ntruffle exec scripts/requestAndReadRandomNumber.js --network \u003cNETWORK\u003e\n```\n\n## Keepers\n\nThe Keepers Consumer contract has one script, to check the upkeep. After deployment, run the following:\n\n```bash\ntruffle exec scripts/checkUpkeep.js --network \u003cNETWORK\u003e\n```\n\nTo see everything in action, you'll want to set up a consumer at [keepers.chain.link](https://keepers.chain.link/sepolia).\n\n## Verify on Etherscan\n\nYou'll need an `ETHERSCAN_API_KEY` environment variable. You can get one from the [Etherscan API site.](https://etherscan.io/apis). If you have it set, your deploy script will try to verify them by default, but if you want to verify any manually, you can run: \n\n```\ntruffle run verify \u003cCONTRACT\u003e --network \u003cNETWORK\u003e\n```\nexample:\n\n```\ntruffle run verify PriceConsumerV3 --network sepolia\n```\n\n# Contributing\n\nContributions are always welcome! Open a PR or an issue!\n\n# Thank You!\n\n## Resources\n\n- [Chainlink Documentation](https://docs.chain.link/)\n- [Truffle Documentation](https://trufflesuite.com/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartcontractkit%2Ftruffle-starter-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartcontractkit%2Ftruffle-starter-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartcontractkit%2Ftruffle-starter-kit/lists"}