Урок 4

Deploying and Testing on the Goerli Testnet

In our journey through Ethereum oracles, we've reached a point where we want to see our contract in action outside the controlled environment of our local development setup. Deployment to a testnet allows us to interact with our contract as if it were on the main Ethereum network, but without the associated costs. In this lesson, we'll walk through the process of deploying our oracle-integrated contract to the Goerli Testnet and test its functionality.

Preparation: Acquiring Testnet Ether and Setting Up Your Environment

Acquiring Testnet Ether

To deploy contracts on the Goerli Testnet, you’ll need Goerli ETH (GoerliETH). While it doesn’t hold any real value, it’s essential for paying gas fees on the testnet.

  1. Metamask: Ensure your Metamask is switched to the Goerli Test Network.

  2. Go to Goerli faucet to request some GoerliETH. Just paste your Goerli Testnet Ethereum address, and you should receive the test ETH shortly.

Configuring Remix for Goerli Testnet Deployment

  1. In Remix, navigate to the Deploy & Run Transactions tab.

  2. For the Environment option, select Injected Provider. This option allows Remix to connect to any network your Metamask is currently set to, which should be Goerli Testnet.

  3. Ensure your contract, OracleIntegratedContract, is selected in the Contract dropdown.

  4. For the Account dropdown, you should see your Goerli Testnet Ethereum address.

Deployment: Getting Your Oracle-Integrated Contract Live on Goerli

Preparing the Contract for Deployment

  1. Before you deploy, you’ll need the address of a Chainlink price feed on the Goerli network. For the sake of this example, we’ll use the ETH/USD Price Feed. You can usually find these addresses in the Chainlink documentation or by exploring the Chainlink contracts on a site like Etherscan. Check here: Testnet Oracles | Chainlink Documentation

  2. Copy the Goerli Testnet address of the Chainlink price feed you want to use. In this case: 0xCC79157eb46F5624204f47AB42b3906cAA40eaB7

  3. Back in Remix, in the Deploy & Run Transactions tab, ensure your contract, OracleIntegratedContract, is selected in the Contract dropdown.

  4. Paste the copied address into the field below the Deploy button (this is where you provide constructor arguments).

Initiating Deployment

  1. Once the price feed address is filled in, click the Deploy button.

  2. Metamask will prompt you to confirm the transaction. Check the gas price and the gas limit to make sure everything looks in order, then confirm the transaction.

  3. After the transaction gets mined, you’ll see a log in Remix with details of the deployment. You can click on the contract address to view the contract on the Goerli Etherscan.

Testing Oracle Responses: Validating the Contract’s Interaction with the Oracle

Now that the contract is deployed, it’s time to test its functions.

  1. In the Deployed Contracts section in Remix, you should see your OracleIntegratedContract.

  2. Expand the deployed contract details to see the available functions.

  3. Before making any calls, you have to detain some LINK on your Goerli Testnet address, you can ask for some here: https://faucets.chain.link/goerli

  4. Once received, to check the balance, you can add LINK to your Metamask on Goerli. Find Here: https://docs.chain.link/resources/link-token-contracts
    Or you can do it manually by adding the contract address like below:

  5. Call the getLatestEthPrice function by clicking on it. It should return the latest ETH price in raw format.

  6. Now, call the getFormattedEthPrice function. This function returns the price in a more readable format.

  7. Lastly, call the safeGetLatestEthPrice function to ensure data fetch safety checks are in place.

Congratulations! You’ve successfully deployed and tested an oracle-integrated contract on the Goerli Testnet. This real-world experience is invaluable, as it brings you a step closer to deploying on the main Ethereum network. In our next lesson, we’ll delve into best practices and common pitfalls to watch out for.

Отказ от ответственности
* Криптоинвестирование сопряжено со значительными рисками. Будьте осторожны. Курс не является инвестиционным советом.
* Курс создан автором, который присоединился к Gate Learn. Мнение автора может не совпадать с мнением Gate Learn.
Каталог
Урок 4

Deploying and Testing on the Goerli Testnet

In our journey through Ethereum oracles, we've reached a point where we want to see our contract in action outside the controlled environment of our local development setup. Deployment to a testnet allows us to interact with our contract as if it were on the main Ethereum network, but without the associated costs. In this lesson, we'll walk through the process of deploying our oracle-integrated contract to the Goerli Testnet and test its functionality.

Preparation: Acquiring Testnet Ether and Setting Up Your Environment

Acquiring Testnet Ether

To deploy contracts on the Goerli Testnet, you’ll need Goerli ETH (GoerliETH). While it doesn’t hold any real value, it’s essential for paying gas fees on the testnet.

  1. Metamask: Ensure your Metamask is switched to the Goerli Test Network.

  2. Go to Goerli faucet to request some GoerliETH. Just paste your Goerli Testnet Ethereum address, and you should receive the test ETH shortly.

Configuring Remix for Goerli Testnet Deployment

  1. In Remix, navigate to the Deploy & Run Transactions tab.

  2. For the Environment option, select Injected Provider. This option allows Remix to connect to any network your Metamask is currently set to, which should be Goerli Testnet.

  3. Ensure your contract, OracleIntegratedContract, is selected in the Contract dropdown.

  4. For the Account dropdown, you should see your Goerli Testnet Ethereum address.

Deployment: Getting Your Oracle-Integrated Contract Live on Goerli

Preparing the Contract for Deployment

  1. Before you deploy, you’ll need the address of a Chainlink price feed on the Goerli network. For the sake of this example, we’ll use the ETH/USD Price Feed. You can usually find these addresses in the Chainlink documentation or by exploring the Chainlink contracts on a site like Etherscan. Check here: Testnet Oracles | Chainlink Documentation

  2. Copy the Goerli Testnet address of the Chainlink price feed you want to use. In this case: 0xCC79157eb46F5624204f47AB42b3906cAA40eaB7

  3. Back in Remix, in the Deploy & Run Transactions tab, ensure your contract, OracleIntegratedContract, is selected in the Contract dropdown.

  4. Paste the copied address into the field below the Deploy button (this is where you provide constructor arguments).

Initiating Deployment

  1. Once the price feed address is filled in, click the Deploy button.

  2. Metamask will prompt you to confirm the transaction. Check the gas price and the gas limit to make sure everything looks in order, then confirm the transaction.

  3. After the transaction gets mined, you’ll see a log in Remix with details of the deployment. You can click on the contract address to view the contract on the Goerli Etherscan.

Testing Oracle Responses: Validating the Contract’s Interaction with the Oracle

Now that the contract is deployed, it’s time to test its functions.

  1. In the Deployed Contracts section in Remix, you should see your OracleIntegratedContract.

  2. Expand the deployed contract details to see the available functions.

  3. Before making any calls, you have to detain some LINK on your Goerli Testnet address, you can ask for some here: https://faucets.chain.link/goerli

  4. Once received, to check the balance, you can add LINK to your Metamask on Goerli. Find Here: https://docs.chain.link/resources/link-token-contracts
    Or you can do it manually by adding the contract address like below:

  5. Call the getLatestEthPrice function by clicking on it. It should return the latest ETH price in raw format.

  6. Now, call the getFormattedEthPrice function. This function returns the price in a more readable format.

  7. Lastly, call the safeGetLatestEthPrice function to ensure data fetch safety checks are in place.

Congratulations! You’ve successfully deployed and tested an oracle-integrated contract on the Goerli Testnet. This real-world experience is invaluable, as it brings you a step closer to deploying on the main Ethereum network. In our next lesson, we’ll delve into best practices and common pitfalls to watch out for.

Отказ от ответственности
* Криптоинвестирование сопряжено со значительными рисками. Будьте осторожны. Курс не является инвестиционным советом.
* Курс создан автором, который присоединился к Gate Learn. Мнение автора может не совпадать с мнением Gate Learn.