ExecuteScriptAtLatestBlock Access API Method
Parameters
Script
string
REQUIRED
The Base64 encoded content of the Cadence script
Arguments
string
REQUIRED
A list of arguments each encoded as Base64 passed in the JSON-Cadence interchange format
Returns
value
string
The result of the executed Cadence script
Request
1package main23import (4"context"5"encoding/json"6"fmt"7"log"8"strconv"910"github.com/onflow/flow/protobuf/go/flow/access"11)121314func main() {1516// Requires authenticating before making the request. Refer to Intro Page on how Authentication can be done.17client, err := getAccessClientWithBasicAuth("ENDPOINT-NAME", "TOKEN_GOES_HERE")18ctx := context.Background()19if err != null {20log.Fatalf("err: %v", err)21}2223// Execute Script at Latest Block24script := []byte(`25pub fun main(a: Int): Int {26return a + 1027}28`)2930// Convert integer to JSON-CDC (Cadence JSON)31arg := 1032// JSON-CDC representation of an integer is a JSON object with "type" and "value" fields33jsonCDC := fmt.Sprintf(`{"type":"Int","value":"%s"}`, strconv.Itoa(arg))3435// Create script arguments36args := [][]byte{[]byte(jsonCDC)}3738req := &access.ExecuteScriptAtLatestBlockRequest{39Script: script,40Arguments: args,41}4243valueResp, err := client.ExecuteScriptAtLatestBlock(ctx, req)44respJSON, err := json.Marshal(valueResp)45if err != null {46log.Fatal("err: ", err)47}48fmt.Println("ExecuteScriptAtLatestBlock response:", string(respJSON))4950}
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free