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

Add a new API on EVM contract to support read-only calls on a transaction context #6800

Open
Tracked by #700
m-Peter opened this issue Dec 11, 2024 · 0 comments · May be fixed by #6838
Open
Tracked by #700

Add a new API on EVM contract to support read-only calls on a transaction context #6800

m-Peter opened this issue Dec 11, 2024 · 0 comments · May be fixed by #6838

Comments

@m-Peter
Copy link
Collaborator

m-Peter commented Dec 11, 2024

Problem definition:
Currently, whenever a user wants to make a Solidity contract call, from within a Cadence transaction, the only available API is CadenceOwnedAccount.call.
It was observed that this API will form a new EVM transaction, even when the user's intention is to simply read the state of a Solidity contract, such as the name | symbol | decimals of an ERC20 contract.
One such example of a transaction we can see here: https://evm.flowscan.io/tx/0x785738aed18cd78885f4c461d351f58543147ae00df320c482096d7eef3deea9.
Since transactions are meant for mutating state on the blockchain, having transactions as the above, is counter-intuitive and should be avoided.

Proposed solution:
To work around this, we should provide the equivalent of EVM.dryRun, but with a more user-friendly interface, as EVM.dryRun expects an RLP-encoded transaction.
Ideally, the interface should look like the following:

fun dryCall(
    from: EVMAddress,
    to: EVMAddress,
    data: [UInt8],
    gasLimit: UInt64,
    value: Balance
): Result {
    return InternalEVM.call(
        from: self.addressBytes,
        to: to.bytes,
        data: data,
        gasLimit: gasLimit,
        value: value.attoflow
    ) as! Result
}

And the function should be defined under the EVM contract itself, not under the CadenceOwnedAccount resource, as this will enforce users to create that resource, and we should avoid this extra computation.
Both EVM.dryCall & EVM.call should be rather intuitive names for Ethereum developers, as the eth_call JSON-RPC endpoint also does not make any state changes.

Regardless of the addition of this new API, we need to make it explicit that CadenceOwnedAccount.call produces EVM transactions, and should be avoid when the intention is to simply read a contract's state.

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

Successfully merging a pull request may close this issue.

1 participant