Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIM-BE-Write methods should be able to return data #770

Open
AgustinRamiroDiaz opened this issue Dec 19, 2024 · 1 comment
Open

SIM-BE-Write methods should be able to return data #770

AgustinRamiroDiaz opened this issue Dec 19, 2024 · 1 comment

Comments

@AgustinRamiroDiaz
Copy link
Contributor

In @kp2pml30 's words

"why only read methods can return values in the simulator and now write methods? in eth write methods can return something as well (and genvm supports it)"

@AgustinRamiroDiaz
Copy link
Contributor Author

AgustinRamiroDiaz commented Jan 7, 2025

Use case:
I would like to get the address of the new contract from a factory contract, which is from a write method

    @gl.public.write
    def create_campaign(
        self,
        title: str,
        goal: str,
        knowledge_base: str,
        rules: str,
        style: str,
        token: str,
        start_datetime_iso: str,
        duration_days: int,
        missions: dict[str, dict[str, typing.Any]],
    ) -> str:
        """
        Creates a new Campaign contract and stores its address.
        Returns the address of the newly created contract.
        """
        # Deploy the new Campaign contract
        salt_nonce = len(self.contract_addresses) + 1  # salt_nonce cannot be 0
        print(f"Salt nonce: {salt_nonce}")
        campaign_address = gl.deploy_contract(
            code=campaign_code.encode("utf-8"),
            args=[
                title,
                goal,
                knowledge_base,
                rules,
                style,
                token,
                start_datetime_iso,
                duration_days,
                missions,
                self.x_id_contract,
                gl.message.sender_account,
            ],
            salt_nonce=salt_nonce,  # Use the current count as nonce
        )

        # Store the contract address
        print(f"Created campaign at address: {campaign_address}")
        self.contract_addresses.append(campaign_address.as_hex)

        return campaign_address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant