Deploy Your Smart Contract via Infura Through Truffle for VS Code Extension
The Truffle for VS Code extension allows Infura users to deploy smart contracts via Infura nodes, without needing to switch between VS Code and the Infura portal.
Our friends at Truffle and Microsoft announced the public release of the Truffle for VS Code extension yesterday. The extension enables VS Code users to build, debug and deploy smart contracts using the Truffle suite of Web3 development tools.
One of the major features supported by the extension is the ability for new and existing Infura users to deploy their smart contracts via Infura nodes without the need to switch between VS Code and the Infura portal.
To use this feature, all you need to do is to create an account on Infura if you don’t already have one and then connect your Infura account as a network under the “Truffle - Networks” tab added by the extension in VS Code.
The Truffle for VS Code extension provides a uniform interface for developers to perform regular tasks without needing to leave VS Code, which in turn enhances developer productivity.
This article assumes that you already have the Truffle for VS Code extension and the necessary dependencies installed. For information on installation, see the official announcement post.
Creating and connecting to a new Infura project using the Truffle for VS Code extension
Let’s say you’ve finished writing your smart contracts and you want to deploy them to a testnet via the Infura Ethereum API. Normally you have to visit the Infura portal to create a new project. You will then need to copy over the RPC endpoints assigned to this newly created project and add them to the `truffle-config` file as your desired networks for deployment.
With the extension, you no longer need to hop between the VS Code interface and the Infura portal. In a few steps, you can create a new Infura project, connect to the newly created project and deploy your smart contract, all within VS Code.
Follow the steps below to create and connect to a new Infura project:
1. Open the VS Code command palette and select Truffle: Create a new network
. This will prompt you to select the network type. Choose the “Infura service” option.
2. Notice a tiny modal at the bottom right corner prompting you to sign into your Infura account. Click the “Sign in” button and grant VS Code permission to access your Infura account.
3. Next, on the text field that appears at the top of VS Code, enter your desired project name and click “Enter”. Then select project visibility (private or public) and click “Enter” to save.
You’ve successfully created and connected a new Infura project to VS Code. We will touch on how to deploy your smart contracts to this network in a later section.
Connect to an existing Infura project using the Truffle for VS Code extension
If you’ve already created a project you wish to use on Infura, you can simply connect to this project by following the steps below:
Open the VS Code command palette and select Truffle: Connect to network
. This will prompt you to select the network type, choose the “Infura service” option.
1. If you’re not already logged in, you will see a tiny modal at the bottom right corner prompting you to sign into your Infura account. Click the “Sign in” button and grant VS Code permission to access your Infura account.
2. If you’re already signed in, a list of your existing Infura projects will appear with an additional option to create a new project. Select your desired project and you’re all set to begin deploying your smart contract.
Deploy your smart contracts to a connected project on Infura using the Truffle for VS Code extension
Now that you have connected your Infura account and have created or imported your desired project for this contract deployment, deploying the contract is easy.
1. Hover over the contract file you wish to deploy and right click to see the options panel. At the bottom of the options panel that appears, select the “Deploy contracts” option.
2. You will be presented with a number of options to choose from, select the project/network pair you want to deploy to e.g `inf_test_project_rinkeby` and hit the “Enter” button.
3. An input field will appear prompting you to enter your desired gas price, which defaults to 100000000000.
4. The next input field that appears will prompt you to paste your account’s mnemonic phrase or generate a new one. Choose an option and hit “Enter.”
The deployment process should kickstart and you should be able to see progress reports on the modal that appears at the bottom right corner.
That’s it, you can now build, debug and deploy smart contracts via Infura without having to leave VS Code.
We hope you’re as excited about this new integration as we are and cannot wait to see how Infura’s user development workflow is improved by this integration.
For more information about this integration, visit the official documentation or the announcement post.
Create a free Infura account today.