ExecuteScriptAtLatestBlock Access API Method
Paramètres
Script
chaîne de caractères
OBLIGATOIRE
Chargement en cours...
Arguments
chaîne de caractères
OBLIGATOIRE
Chargement en cours...
Retours
valeur
chaîne de caractères
Chargement en cours...
Demande
1paquet principal23import (4« contexte »5« encoding/json »6« fmt »7« journal »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}
1paquet principal23import (4« contexte »5« encoding/json »6« fmt »7« journal »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}
Vous n'avez pas encore de compte ?
Créez votreendpoint Quicknode endpoint quelques secondes et commencez à développer
Commencez gratuitement