# Struggling with ExecuteScriptAtBlockHeight

**URL:** <https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097>\
**Category:** Users Troubleshooting\
**Created:** [February 28, 2021, 9:39pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097 "2021-02-28T21:39:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![phereford](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/phereford/32/306_2.png) [@phereford](https://forum.flow.com/u/phereford)\
**Post date:** [February 28, 2021, 9:39pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/1 "2021-02-28T21:39:40Z")

</div>

Hey everyone!

I have been enjoying learning about Flow and all of the intricacies in accessing data on the blockchain.

So far I have been successfully able to execute scripts on the recent block and on specific block IDs. I have not been able to successfully execute it when attempting to execute the script across a range of block heights.

The error I am getting is:

```auto
%GRPC.RPCError{message: "3 errors occurred:%0A%09* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527: trie with the given rootHash [96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527] not found%0A%09* rpc error: code = Internal desc = failed to execute the script on the execution node execution-4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd@execution-003.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527: trie with the given rootHash [96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527] not found%0A%09* rpc error: code = Internal desc = failed to execute the script on the execution node execution-9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4@execution-001.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527: trie with the given rootHash [96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527] not found%0A%0A", status: 2}

```

I am using Elixir and generated the gRPC client using the flow protobuf files.

Any advice on getting past this would be helpful.

For reference, the script I am trying to use is passing an `Address` as an argument and I think that is where this is failing. From what I can see, I have been able to GetAccountAtLatestBlock just fine with an sending bytes from the gRPC generated client to the blockchain. Trying to send the address to a script has been giving me headaches however.

Thanks!

---

<div class="post-metadata">

**Author:** ![pete](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/pete/32/191_2.png) [@pete](https://forum.flow.com/u/pete)\
**Post date:** [March 2, 2021, 4:44am UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/2 "2021-03-02T04:44:29Z")

</div>

Hey @phereford!

Out of curiosity, is this error happening every time? The error message actually looks more like a bug in the node rather than your code.

Can you let me know how easy it is to reproduce?

BTW, cool to hear that you’re using Elixir!

---

<div class="post-metadata">

**Author:** ![bigoper](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bigoper/32/307_2.png) [@bigoper](https://forum.flow.com/u/bigoper)\
**Post date:** [March 2, 2021, 4:44pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/3 "2021-03-02T16:44:59Z")

</div>

Hi,

I’m experiencing the same issue here.  
I was wondering if you were able to recover from it?

Thanks!

---

<div class="post-metadata">

**Author:** ![phereford](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/phereford/32/306_2.png) [@phereford](https://forum.flow.com/u/phereford)\
**Post date:** [March 2, 2021, 9:25pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/4 "2021-03-02T21:25:46Z")

</div>

Hey @pete !

So, the error message happens when I am trying to pass in an address to the script.

From the protobuf source, I was able to generate the following client: [GitHub - phereford/flow](https://github.com/phereford/flow)

Here is a gist of the code I have been toying with to get it working:

> <https://gist.github.com/phereford/ff256b2e81c6e43d9e01255f03f636c2>

What works in the gist:

- Getting latest block
- Getting events for a specific height range
- Getting an Account at the Latest block

What doesnt work:

- ExecuteScriptAtLatestBlockRequest
- ExecuteScriptAtBlockHeightRequest
- Getting an account at a specific block height

In the gist I have put the error messages that I have been receiving. the \*\* MatchError is an elixir error stating that my tuple doesnt match as it is expecting {:ok, Struct} and instead getting {:error, GRPC.Error}.

Any advice here would be super helpful!

Last note: I have been able to execute a script against a block height that takes no arguments. As soon as I add arguments to the function, it fails.

---

<div class="post-metadata">

**Author:** ![phereford](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/phereford/32/306_2.png) [@phereford](https://forum.flow.com/u/phereford)\
**Post date:** [March 2, 2021, 9:38pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/5 "2021-03-02T21:38:02Z")

</div>

Hey @bigoper ,

I havent quite gotten past it yet. My hunch as to what is happening is that the script is expecting something in a specific type but the generated gRPC client only allows us to send `:binary` as arguments. Whats tricky is I have converted the address from a string to bytes and that doesnt work quite as expected.

---

<div class="post-metadata">

**Author:** ![weaver1045](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@weaver1045](https://forum.flow.com/u/weaver1045)\
**Post date:** [March 3, 2021, 3:12am UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/6 "2021-03-03T03:12:47Z")

</div>

Hey @bigoper

I get a similar issue using python’s grpc\_tools.protoc on the proto files. I can run Ping, GetLatestBlockHeader, and GetEventsForHeightRange without an issue.

When I run ExecuteScriptAtBlockHeight I get a very similar error:

```
block_height = int(12408061)
script = """
pub fun main(): String {
  return "Hello World"
}
"""

req = ExecuteScriptAtBlockHeightRequest()
req.block_height = block_height
req.script = str.encode(script)
resp = stub.ExecuteScriptAtBlockHeight(req)

```

Error:

```
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "3 errors occurred:
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4@execution-001.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found

"
	debug_error_string = "{"created":"@1614739406.441909678","description":"Error received from peer ipv4:35.226.224.190:9000","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"3 errors occurred:\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4@execution-001.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found\n\n","grpc_status":2}"
>
```

---

<div class="post-metadata">

**Author:** ![weaver1045](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@weaver1045](https://forum.flow.com/u/weaver1045)\
**Post date:** [March 3, 2021, 3:28pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/7 "2021-03-03T15:28:33Z")

</div>

This works fine but doesn’t happen over gRPC.

HelloWorld.cdc

```
pub fun main(): String {
  return "Hello World"
}

```

shell:

```
$ flow scripts execute HelloWorld.cdc --host access.mainnet.nodes.onflow.org:9000
{"type":"String","value":"Hello World"}
```

---

<div class="post-metadata">

**Author:** ![bigoper](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bigoper/32/307_2.png) [@bigoper](https://forum.flow.com/u/bigoper)\
**Post date:** [March 3, 2021, 3:36pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/8 "2021-03-03T15:36:23Z")

</div>

@weaver1045

I was able to resolve it (using some help)  
[https://github.com/rrrkren/topshot-sales/pull/4](https://github.com/rrrkren/topshot-sales/pull/4)

Due to the increasing amount of transactions, the current “window” (block height) is not valid anymore.  
You must use a “smaller sized window” (500 -\> 100), which will be valid (exists).

I hope this helps.

P.S  
Can you share a link to your implementation on Git?

---

<div class="post-metadata">

**Author:** ![phereford](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/phereford/32/306_2.png) [@phereford](https://forum.flow.com/u/phereford)\
**Post date:** [March 3, 2021, 4:28pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/9 "2021-03-03T16:28:59Z")

</div>

@weaver1045 I was able to do the same as above to get some successful queries working. I was still unable to execute scripts that took arguments though.

---

<div class="post-metadata">

**Author:** ![weaver1045](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@weaver1045](https://forum.flow.com/u/weaver1045)\
**Post date:** [March 3, 2021, 8:49pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/10 "2021-03-03T20:49:11Z")

</div>

@bigoper I was able to get the Go code to work using a 100 window.

@phereford I have the same problem now on the python side. I can get ExecuteScriptAtBlockHeight to work if I don’t pass any arguments. Getting “error: invalid argument at index 0” back from all 3 execution nodes if I try to send arguments.

Code:

```
from flow.access.access_pb2 import *
from flow.access.access_pb2_grpc import *
from flow.execution.execution_pb2_grpc import *

channel = grpc.insecure_channel('access.mainnet.nodes.onflow.org:9000')
stub = AccessAPIStub(channel)

r = GetLatestBlockRequest()
response = stub.GetLatestBlock(r)

block_height = response.block.height

script = b"""

pub fun main(m:String): String {
  return m
}

"""

position0 = b"Hello Flow"

req = ExecuteScriptAtBlockHeightRequest()
req.block_height = block_height
req.script = script

req.arguments.extend([position0])
resp = stub.ExecuteScriptAtBlockHeight(req)
print(resp)

```

Error:

```
3 errors occurred:
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:
error: invalid argument at index 0
--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2

	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:
error: invalid argument at index 0
--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2

	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd@execution-003.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:
error: invalid argument at index 0
--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2

"
	debug_error_string = "{"created":"@1614804245.123604012","description":"Error received from peer ipv4:35.226.224.190:9000","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"3 errors occurred:\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:\nerror: invalid argument at index 0\n--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2\n\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:\nerror: invalid argument at index 0\n--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2\n\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd@execution-003.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:\nerror: invalid argument at index 0\n--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2\n\n\n","grpc_status":2}
```

---

<div class="post-metadata">

**Author:** ![pete](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/pete/32/191_2.png) [@pete](https://forum.flow.com/u/pete)\
**Post date:** [March 4, 2021, 8:29am UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/11 "2021-03-04T08:29:32Z")

</div>

Script arguments are formatted as JSON-CDC values. You can see the spec here: [JSON-Cadence Data Interchange Format - Flow Documentation](https://docs.onflow.org/cadence/json-cadence-spec#address)

@phereford In your case you’ll want to change the address to this:

```auto
address = "{ \"type\": \"Address\", \"value\": \"0x7b0aac240b2bacda\" }"

```

@weaver1045 Same goes for Python. We might have some code that helps with this, though – I’ll check!

@weaver1045

---

<div class="post-metadata">

**Author:** ![phereford](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/phereford/32/306_2.png) [@phereford](https://forum.flow.com/u/phereford)\
**Post date:** [March 6, 2021, 2:10pm UTC](https://forum.flow.com/t/struggling-with-executescriptatblockheight/1097/12 "2021-03-06T14:10:16Z")

</div>

@pete Thank you so much!!! Verified this works.

I knew I was missing something.
