rsksmart / rskj

RSKj is a Java implementation of the Rootstock protocol.
https://rootstock.io
GNU Lesser General Public License v3.0
669 stars 267 forks source link

RPC problem when deploying contracts with Foundry #2548

Closed chrisarevalodev closed 4 months ago

chrisarevalodev commented 4 months ago

Issue when deploying contracts in RSK with Foundry

I’m currently working on a starter kit with Foundry for writing, testing, and deploying contracts on the Rootstock network. In this starter kit, I have implemented a sample flow for testing and deploying a mock ERC20 token, providing developers with a practical example.

Deployment command

forge script script/MockERC20.s.sol:MockERC20Script --rpc-url $RSK_RPC_URL --legacy --broadcast

Deployment script

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import {Script, console} from "forge-std/Script.sol";
import {MockERC20} from "../src/MockERC20.sol";

contract MockERC20Script is Script {
  function setUp() public {}

  function run() public {
    uint privateKey = vm.envUint("PRIVATE_KEY");
    address account = vm.addr(privateKey);

    vm.startBroadcast(privateKey);

    new MockERC20("RSKToken", "RSK", account);

    vm.stopBroadcast();
  }
}

Issue with Deployment

When I run the deployment command, the transaction starts, and a progress bar appears in the CLI. However, after some time, presumably due to a timeout, I encounter the following error:

Error: 
Transaction dropped from the mempool: # a transaction id

Upon checking the transaction ID in the RSK testnet explorer, I can see that the transaction was successful. I have also tested a method of the deployed contract, and it works as expected. Despite this, the error message in the console can be confusing for developers.

Possible cause

The issue seems to be related to the RPC. When I switch to an RPC URL from another network, the error no longer appears. Our hypothesis is that Foundry might be waiting for a completion event that the RPC API, which does not support WebSocket, fails to provide. However, this hypothesis might not be entirely accurate.

Repository

For testing and further details, you can find the starter kit repository here: https://github.com/chrisarevalo11/rsk-foundry-starter-kit.

jurajpiar commented 4 months ago

Panic is over. This message is not coming from RSKj, but from foundry. My bad, I suggested to create an issue before checking this more in-depth.