How DevNets Accelerate Local Smart Contract Development

https://blog.tenderly.co/using-devnets-in-local-smart-contract-development/

Local development frameworks like Hardhat, Truffle, or Foundry have immensely simplified smart contract development. They give developers an environment and essential tools for easier building and testing of dapps.

But when it comes to deployment, speed bumps are inevitable. Lengthy transaction execution on public testnets, local node management, and waiting on faucets to acquire test ETH — all hindering productivity.

DevNets offer a streamlined, zero-setup development environment for smart contracts that smoothly integrates into your current workflow. This private and isolated development playground enables you to test smart contracts against production data, complete with indispensable debugging tools.

🚀
Sign in to Tenderly and spin up a DevNet in seconds. It’s free, so why not give it a go?

Seamless integration with Hardhat, Truffle, and Foundry

DevNets supports all popular local development frameworks, including Hardhat, Foundry, Truffle, and Brownie. There’s no need for additional setup or management. Tenderly handles everything in the background.

To show you how DevNets easily fit into your existing workflows, let’s use Hardhat as an example. Integrating DevNets into your Hardhat project is as simple as tweaking your hardhat.config.js file.

First, you need to spin up a DevNets via the Tenderly Dashboard, copy the auto-generated RPC URL, and add it to your Hardhat configuration like so:

module.exports = {
  networks: {
    devnet: {
      url: "YOUR_DEVNET_JSON_RPC_URL",
      chainId: 1,
    }
  }
};

This simple change opens the door to Tenderly’s ecosystem of robust development and debugging tooling in your local development, along with access to production data from 30+ networks.

0:00

/

For a more streamlined approach, you can use the tenderly devnet spawn-rpc CLI command. This command will initiate a process that automatically spins up a DevNet and injects the URL into Hardhat.

💡
Get started with DevNets in your local development with this sample Hardhat project from our GitHub repo. It comes with a sample contract, a test for the contract, and a script that deploys the contract.

Execute transactions on production data without delays

DevNets provide a Mainnet-like testing environment that mirrors on-chain conditions. This ensures that your smart contracts behave as expected when deployed to the Mainnet, reducing the risk of unexpected issues arising in production.

You can build, test, and deploy on production data from over 30 networks supported by Tenderly. DevNets also give you complete control over the network state, allowing you to modify the headers, blocks, and other elements to fit your requirements.

0:00

/

Transaction execution on DevNets is instantaneous. Hosted on Tenderly’s lighting-fast infrastructure, DevNets process transactions in milliseconds and eliminate infrastructure management overhead from your pipeline.

When you spin up a DevNets, you automatically get 10 unlocked accounts, each preloaded with 100 test ETH to run any number of transactions. In case you run out, you can use our unlimited faucet to top up the balance to any amount of test ETH you need.

Or you can use custom RPC endpoints tenderly_setBalance and tenderly_addBalance to do so programmatically.

A list of all standard and custom RPC endpoints can be found in the documentation.

Access to Tenderly tooling in local development

In addition to robust development infrastructure, DevNets bring the power of the Tenderly tooling ecosystem to your local development.

You get access to our visual Debugger on top of the tools you get out-of-the-box with your preferred development framework. This means you are no longer limited to console logging as the primary debugging method.

With each DevNet environment, you get access to the following tools:

  • Private block explorer: View all transactions executed within the DevNet environment.
  • Visual Debugger: Get a human-readable representation of errors, function calls, execution traces, emitted events, and expressions directly from the Dashboard.
  • Gas Profiler: Understand how transactions consume compute resources with a detailed breakdown of gas usage by each function call.
  • Transaction Simulator: Re-run failed transactions by changing some or all parameters and observing the outcomes.
  • Collaboration features: Leave comments on problematic lines of code and get the entire team involved in troubleshooting.
  • RPC calls overview: See a detailed breakdown of all RPC calls made to the node within your DevNet to get a deeper understanding of how resources are consumed.
  • Unlimited faucet: Add as much test ETH as you need to any of the 10 unlocked accounts on your DevNet. Use the handy Tenderly Faucet or call our custom RPC methods to top up your accounts.

Why use DevNets in local dapp development?

DevNets bring privacy, flexibility, advanced tooling, and collaborative features to the table, each aspect tailored to optimize your development experience. Here’s a closer look at the key benefits of using DevNets in local smart contract development.

1. Complete privacy and isolation

DevNets offer a secure and private environment for developing and testing smart contracts. This is crucial if you’re working on proprietary projects or handling sensitive data that should not be exposed on public networks. By using DevNets, you can ensure that your work remains private throughout the development process.

2. Independence from public testnets

DevNets allow for rapid testing and debugging of smart contracts without the latency of public testnets. Transactions on DevNets are executed blazingly fast, enabling you to test and iterate on smart contracts more efficiently. DevNets also eliminate the overhead of mining for test ETH by providing an easy way to add funds to accounts.

3. Access to Tenderly tooling

DevNets give you access to Tenderly’s Debugger, Gas Profiler, Simulator, and other tools in local development. With these tools now available in local development, you can identify issues much faster and optimize your smart contracts for better performance based on data-driven insights.

4. Collaborative development

DevNets are also a collaborative environment where developers can work together, communicate, and exchange feedback directly in the Dashboard. Collaboration is key to eliminating silos and enabling distributed teams to work more efficiently when troubleshooting, something not before possible in local development.

Ready to spin up your first DevNet?

Tenderly DevNets offer a powerful solution to enhance local development and speed up your pipeline by smoothly integrating into your existing workflows.

To get started, log into your Dashboard, navigate to DevNets, and spin up your first completely private and isolated development environment on any of the 30+ supported networks.

If you have questions or need assistance with integrating DevNets, be sure to join our Discord channel or message our support team.

Tenderly DevNets: Develop and Test with Mainnet Data

https://blog.tenderly.co/tenderly-devnets-develop-and-test-with-mainnet-data/

Tenderly DevNets are here! A managed, zero-setup environment for smart contract development with handy debugging tools built in. Plus, instantly available unlimited supplies of test tokens.

Powered by the same infrastructure running Tenderly, DevNets give you access to Tenderly’s leading suite of development and debugging tools. Now, you can use our visual Debugger, Transaction Trace, Gas Profiler, Simulator, and many other tools within a unified development environment.

Why DevNets?

Developing smart contracts locally often involves slow feedback loops, limited team collaboration, and a lack of visibility. When debugging, developers are usually left with console logging as the primary debugging method, which can slow down development.

DevNets address these issues by seamlessly integrating into your local development and giving you access to powerful tools that speed up your workflows.

Tenderly DevNets: Develop and Test with Mainnet Data
Tenderly DevNets dashboard

As a managed, zero-setup environment, DevNets eliminate the need to install third-party software on your local machine.

In contrast to public testnets, DevNets give you an isolated environment with complete privacy and control over who has access. You can be confident that your data and smart contracts remain private while ensuring everyone on your team is working on the same template.

On top of this, you’re building on production data – an exact replica of the latest state of the chosen network. This ensures accurate testing outcomes without performance degradation often found in public testnets.

Tenderly DevNets: Develop and Test with Mainnet Data
Illustration of how Tenderly DevNets work

Using DevNets in your local development also means you’re no longer limited to just console logging when debugging. DevNets are fully integrated into Tenderly’s powerful development and debugging tools out of the box.

Tenderly DevNets: Develop and Test with Mainnet Data
Debug transactions directly within DevNets

With access to your visual Debugger within DevNets, you can dig deeper into individual transactions to pinpoint failures. The Transaction Trace allows you to inspect and debug transactions down to the very last OP code and JSON-RPC call, giving you complete visibility.

Additionally, you get a private block explorer with every DevNet you deploy that provides a user-friendly overview of all your transactions.

Tenderly DevNets: Develop and Test with Mainnet Data
Private block explorer within DevNets

But before you can send transactions, you need test accounts with sufficient test ETH. On public testnets, acquiring test ETH involves using faucets and waiting for the test ETH to be mined. Additionally, you may encounter situations where you don’t have enough ETH to run large transactions.

DevNets address this problem by providing you with 10 test accounts, each preloaded with 100 test ETH. If you require more, you can use the unlimited faucet to add any amount of test ETH to any account. This ensures that a lack of test ETH will never hinder your development pace.

What you get with DevNets out of the box

DevNets are all about streamlining your development process and helping you accelerate your pipeline. The key benefits include the following:

  • Zero-setup environment: Start coding, developing, and testing immediately with instant access to a production node without any rate limits. No third-party dependencies to install or manage.
  • Access to Tenderly development tooling: Supercharge your development with instant access to Tenderly’s visual Debugger, Gas Profiler, Transaction Trace, and Simulator.
  • Available on 30+ networks: Spawn a DevNet on any of the 30+ Tenderly-supported networks and build on top of accurate production data with confidence.
  • Support for popular development frameworks: Develop using your favorite frameworks, such as HardHat, Foundry, Truffle, or Brownie, and let Tenderly handle the rest.
  • Reusable templates: Save your DevNets configurations as reusable templates and spin up a new network with a fresh state without unnecessary manual steps.

To explore other benefits and features, check out our in-depth documentation.

Quick starter guide: How to spin up your first DevNet

Let’s show you how to spin up your first DevNet environment in a couple of easy steps.

  1. Sign up for a free Tenderly account: Head over to the registration page to create your free account or log in.
  2. Access DevNets: Click on “DevNets” from the lefthand menu. You’ll be redirected to the DevNets dashboard.

Next, follow the steps in this video to learn how to create a DevNets template and spin up your first DevNet environment.

0:00

/

Start building on DevNets today

We’re super excited to see what incredible projects you’ll build with Tenderly DevNets!

So, why wait? Take DevNets for a spin! 🚀

Got questions or feedback?

Join our community on Discord, follow us on Twitter @TenderlyApp, or shoot us an email at support@tenderly.co.

Automate Transaction Sending with Web3 Actions and Web3 Gateway

https://blog.tenderly.co/web3-gateway-access-integrated-into-web3-actions/

Web3 Actions enable dapps to monitor on-chain events and automatically trigger the execution of custom code when the event occurs. With built-in support for Ethers.js, Web3 Actions also allow you to call different RPCs and interact with the blockchain.

To streamline this process even further, we integrated access to Tenderly’s production node directly into Web3 Actions, eliminating the need to manage external RPC URLs and access keys.

With just a single line of code, you can now access the Mainnet or supported testnets directly from your Web3 Action function code and automatically send transaction or query on-chain data.

Web3 Actions & Web3 Gateway: A Quick Refresher

Before digging deeper, let’s do a quick recap of what Web3 Actions and Web3 Gateway are and how they work together to remove friction in your dapp development workflows.

Web3 Actions are serverless functions that allow you to respond to on-chain events with custom code. Web3 Actions can help you connect on-chain and off-chain systems and have them work together to power your dapp.

For example, you can use Web3 Actions to automate transaction sending, gather on-chain data for analytics, or build advanced on-chain monitoring systems. For more details on how Web3 Actions work, our documentation has you covered.

On the other side, Web3 Gateway is Tenderly’s node as a service that provides reliable, stable, and extremely fast blockchain access. This is a production node that can be used to send transactions, deploy contracts, or query on-chain data. Web3 Gateway gives you a single RPC URL of the network you want to access, simplifying the process of connecting to the Mainnet or supported testnets.

By integrating Web3 Gateway access into Web3 Actions, you no longer have to include sensitive data like access keys in your Web3 Action functions. This makes your dapps more secure and easier to maintain. In fact, all you need is a single line of code to enable network access for your dapp.

Transaction simulations available in Web3 Gateway

Need to test out if your transaction will go through before sending it on-chain and risking a failure? We developed a custom RPC endpoint within Web3 Gateway to give you the ability to run simulations on any number of transactions through the same RPC URL.

The tenderly_simulateTransaction RPC endpoint allows you to simulate transactions against the latest state. No need to use different RPC URLs for simulations and transaction sending.

All you have to do is add the Web3 Gateway URL to your Web3 Action function code and call the tenderly_simulateTransaction RPC endpoint. Once you’re happy with the results of the simulation, simply switch the call to eth_sendRawTransaction and send the transaction.

Benefits of Accessing Web3 Gateway through Web3 Actions

There are several use cases in which accessing Web3 Gateway through Web3 Actions can come in handy, including automated transaction sending, building advanced blockchain monitoring systems, and maintaining the integrity of your dapp.

  • Automatically send transactions in response to on-chain events: Web3 Actions allow you to monitor certain on-chain events, analyze the state, and react to any changes by automatically sending transactions. If you’re building components for a system, Web3 Actions can help you simplify the development process and improve the performance and security of your dapp.
  • Build an advanced monitoring system for your dapp and smart contracts: With access to Tenderly’s node built directly into Web3 Actions, it’s much easier to build components for a complex smart contract monitoring system. It enables you to combine transaction data with on-chain data which you gather using Web3 Actions. In combination with Web3 Action Storage, this also enables you to perform additional analysis and indexing.
  • Ensure the integrity of your dapp: Web3 Actions allow you to periodically and programmatically check the state of your dapps and ensure that the system is functioning as intended. For example, in case of a hack, you are instantly notified about specific transactions that might be causing undesired effects, allowing you to react quickly and prevent further damage.

How to access Web3 Gateway through Web3 Actions

Web3 Actions are designed to execute custom code when a certain on-chain event happens. This custom logic is Javascript or Typescript code that is added as the function of your Web3 Action. A function is a term used within Web3 Actions to refer to custom code that gets executed when the Web3 Action is triggered.

If you need more details about the different Web3 Actions components, such as events, triggers, and functions, our documentation has all the resources you need to get you up to speed.

Setting up a Web3 Action to access the Mainnet

Open up your Dashboard and go to Web3 Actions. Get started by selecting the Trigger Type. This is the type of event that will serve as the trigger for your custom code to run.

Automate Transaction Sending with Web3 Actions and Web3 Gateway
Web3 Action configuration wizard

Based on the Trigger Type you select, the function code field will be pre-populated with the boilerplate code needed for the Web3 Action to work.

To unlock access to Web3 Gateway within your Web3 Actions function, you need to define a single variable within the default actionFn variable like so.

const defaultGatewayURL = context.gateways.getGateway(Network.MAINNET);

To illustrate how this works, we are accessing the Mainnet through Web3 Gateway to get the block number of the latest block. Whenever a new block is mined, this Web3 Action will run this code to get the number of the block and log it to the console.

Automate Transaction Sending with Web3 Actions and Web3 Gateway
Adding custom code to the Web3 Action function

Accessing Web3 Gateway within Web3 Actions

In the example above, we’re defining the defaultGatewayURL variable, which contains the Web3 Gateway RPC URL and the secret key. We’re also using Ethers.js to call the RPC URL, get the latest block number with the getBlockNumber function, and log the result to the console.

If you want to test out the example, you can copy/paste the code snippet below into your Web3 Action function and see it in action.

// Required libraries that must be included for the code to work
const ethers = require("ethers")
const { Network } = require("@tenderly/actions")
// Do not change the default 'actionFn' name.
const actionFn = async (context, blockEvent) => {
	// Setting a variable that will store the Web3 Gateway RPC URL and secret key
	const defaultGatewayURL = context.gateways.getGateway(Network.MAINNET);
	// Using the Ethere.js provider class to call the RPC URL
	const provider = new ethers.providers.JsonRpcProvider(defaultGatewayURL);
	// Logging the block number of the latest mined block
	console.log(await provider.getBlockNumber())
    
}
// Exporting the default module. Do not change this.
module.exports = { actionFn }

After letting the Web3 Action run for a while, we can check the Dashboard to see the Execution History. The Logs panel indicates that the Web3 Action is logging the latest block number to the console as expected.

Automate Transaction Sending with Web3 Actions and Web3 Gateway
Results of a successfully executed Web3 Action

This was a pretty simple example showing the feature in action. For a more advanced example of how to access Web3 Gateway through your Web3 Actions, check out this practical tutorial. The tutorial shows you how to find contracts with the same bytecode that were deployed by another contract using Web3 Actions and Web3 Gateway.

The complexities simplified into a single line of code

Access to Web3 Gateway gateways is enabled through the context object in Web3 Actions. To dig deeper into the context object, take a look at the documentation.

gateways gives you access to the getGateway() function that allows you to fetch a specific network. This function accepts one required argument — the name of the network you want to access.

Network is also an object that contains all available networks supported in Web3 Gateway.

If you want to access the Mainnet, for example, you can simply define Network.MAINNET. This same format applies to other supported networks within Web3 Gateway, like Sepolia and Goerli.

Notice that you are not required to include RPC secret keys in your function code. Tenderly takes care of the secrets and everything else in the background for you, helping you write cleaner and more secure code.

In case you need to reset your RPC secret keys, the changes will automatically be reflected across your Web3 Action functions.

There’s no need for you to manually update the secret keys, as you would if you used third-party node providers in your Web3 Action functions. This way, you’re also eliminating the risk of something breaking unintentionally when you reset your RPC secret keys.

Build and deploy Web3 Actions faster via CLI

You are not limited to using the Dashboard to deploy and manage Web3 Actions. If you are building a more complex system and prefer to do things with code, you can also develop Web3 Actions locally and deploy them via CLI.

Check out the full list of CLI commands for deploying and managing Web3 Actions in our documentation.

Ready to get started with Web3 Actions and Web3 Gateway?

If you have a Tenderly account, you get access to Web3 Actions and Web3 Gateway out of the box. Log into your account or create an account if you don’t have one, and launch your first Web3 Action with a couple of clicks.

Web3 Gateway will automatically be configured on your account, giving you instant access to the Mainnet and testnets without additional set-up.