Skip to content

Commit 5afbaa0

Browse files
authored
Merge pull request #8290 from onflow/leo/v0.44.14-access-node-fix-script-execution-with-evm
Access node fix script execution with evm
2 parents a7bf11e + ee6c8e9 commit 5afbaa0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

fvm/script.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ func (executor *scriptExecutor) executeScript() error {
203203
chainID := executor.ctx.Chain.ChainID()
204204

205205
if executor.ctx.EVMEnabled {
206+
// Setup InternalEVM in both environments because:
207+
// - Scripts execute in ScriptRuntimeEnv
208+
// - But system contract invocations (e.g., getAccount().balance) use TxRuntimeEnv
209+
210+
// Setup InternalEVM in ScriptRuntimeEnv (for script execution)
206211
err := evm.SetupEnvironment(
207212
chainID,
208213
executor.env,
@@ -211,6 +216,21 @@ func (executor *scriptExecutor) executeScript() error {
211216
if err != nil {
212217
return err
213218
}
219+
220+
// Setup InternalEVM in TxRuntimeEnv (for system contract invocations)
221+
// This solves the problem where FlowServiceAccount (which imports EVM) needs
222+
// InternalEVM to be available during dependency checking when invoked via
223+
// system contracts (e.g., getAccount().balance). Without this, type checking
224+
// fails with "cannot find variable in this scope: `InternalEVM`" because
225+
// system contract invocations use TxRuntimeEnv, not ScriptRuntimeEnv.
226+
err = evm.SetupEnvironment(
227+
chainID,
228+
executor.env,
229+
rt.TxRuntimeEnv,
230+
)
231+
if err != nil {
232+
return err
233+
}
214234
}
215235

216236
value, err := rt.ExecuteScript(

0 commit comments

Comments
 (0)