ExecuteScriptAtLatestBlock Access API Method
Parámetros
Script
cadena
OBLIGATORIO
Cargando...
Arguments
cadena
OBLIGATORIO
Cargando...
Devoluciones
valor
cadena
Cargando...
Solicitud
1paquete principal23import (4«contexto»5«encoding/json»6«fmt»7«registro»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()19si err != nil {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)45si err != nil {46log.Fatal("err: ", err)47}48fmt.Println("ExecuteScriptAtLatestBlock response:", string(respJSON))4950}
1paquete principal23import (4«contexto»5«encoding/json»6«fmt»7«registro»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()19si err != nil {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)45si err != nil {46log.Fatal("err: ", err)47}48fmt.Println("ExecuteScriptAtLatestBlock response:", string(respJSON))4950}
¿Aún no tienes una cuenta?
Crea tu punto de conexión de Quicknode en cuestión de segundos y empieza a desarrollar
Empieza gratis