# Struggle with executing a Cadence Script

**URL:** <https://forum.flow.com/t/struggle-with-executing-a-cadence-script/4389>\
**Category:** 🏄🏻‍♀️ Cadence\
**Created:** [February 27, 2023, 10:10am UTC](https://forum.flow.com/t/struggle-with-executing-a-cadence-script/4389 "2023-02-27T10:10:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alextoporov](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@alextoporov](https://forum.flow.com/u/alextoporov)\
**Post date:** [February 27, 2023, 10:10am UTC](https://forum.flow.com/t/struggle-with-executing-a-cadence-script/4389/1 "2023-02-27T10:10:31Z")

</div>

Hello!  
I’m just trying to execute a cadence script via API call from here

> **[Flow Blockchain](https://developers.flow.com/http-api/#tag/Scripts/paths/~1scripts/post)**
>
> Your resource for everything you'll need to build in Flow

I want to know how should I execute script for example to know about _“Get All Info about a single Delegator”_ from here:

> <https://github.com/onflow/flow-core-contracts/blob/master/transactions/idTableStaking/delegation/get_delegator_info.cdc>

How should I pass request body schema?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/andrea/32/607_2.png) [@andrea](https://forum.flow.com/u/andrea)\
**Post date:** [February 28, 2023, 3:05pm UTC](https://forum.flow.com/t/struggle-with-executing-a-cadence-script/4389/2 "2023-02-28T15:05:13Z")

</div>

Hey there!

## Pre-requisites

You can get the address of the `0xIDENTITYTABLEADDRESS` from [Flow Staking Contract Reference | Flow Blockchain](https://developers.flow.com/flow/core-contracts/staking-contract-reference). For mainnet, that’s `0x8624b52f9ddcd04a`

I also recommend you use an app like Postman or Insomnia and load the OpenAPI spec. Here’s the URL to import: [https://raw.githubusercontent.com/onflow/flow/master/openapi/access.yaml](https://raw.githubusercontent.com/onflow/flow/master/openapi/access.yaml)

It will make it easier to test and debug your requests.

## Simple Example

In response to your question, here’s an example script sent through the REST API. In this case, we will run the `getNodeIDs()` method so we can get a list of NodeIDs and use one of the IDs to show you how to pass in an argument later.

Cadence script:

```auto
import FlowIDTableStaking from 0x8624b52f9ddcd04a

pub fun main(): [String] {
    return FlowIDTableStaking.getNodeIDs()
}

```

To be sent via the API, it needs to be Base64 encoded (using a site like: [https://www.base64encode.org/](https://www.base64encode.org/))

```auto
aW1wb3J0IEZsb3dJRFRhYmxlU3Rha2luZyBmcm9tIDB4ODYyNGI1MmY5ZGRjZDA0YQoKcHViIGZ1biBtYWluKCk6IFtTdHJpbmddIHsKICAgIHJldHVybiBGbG93SURUYWJsZVN0YWtpbmcuZ2V0Tm9kZUlEcygpCn0=

```

You would then construct the request as follows:

```auto
curl --request POST \
  --url https://rest-mainnet.onflow.org/v1/scripts \
  --header 'Content-Type: application/json' \
  --data '{
  "script": "aW1wb3J0IEZsb3dJRFRhYmxlU3Rha2luZyBmcm9tIDB4ODYyNGI1MmY5ZGRjZDA0YQoKcHViIGZ1biBtYWluKCk6IFtTdHJpbmddIHsKICAgIHJldHVybiBGbG93SURUYWJsZVN0YWtpbmcuZ2V0Tm9kZUlEcygpCn0=",
  "arguments": []
}'

```

The API would return a response like:

```auto
eyJ2YWx1ZSI6W3sidmFsdWUiOiIyMjk0YzMyYmViNDZiMTJjZDdiYzY3ZTQwZWRhMzY3ZjZmMzg0ODg1OTRjMjkzNDc2YjQxYTAzNTY5NGE2YzgxIiwidHlwZSI6IlN0cmluZyJ9LHsidmFsdWUiOiI1ZTEzYmE3NTZhN2NjMzQxOGE1YzMzMzZiZjA1OTMzZWY1YmNmNjYzMzQyZTM0OGNlZGM4NjAwMGRhMTEzY2ExIiwidHlwZSI6IlN0cmluZyJ9LHsidmFsdWUiOiIzOGFmYTY4YmU5ZjVhOWU0Y2FhYWJkZDcyOTFmY2U0MDBiYTA2NGRhZmIzNDYzYmU0ZTFmMTVjNzBjMWEzY2NmIiwidHlwZSI6IlN0cmluZyJ9...

```

Which if you Base64 decode, would be:

```auto
{
   "value":[
      {
         "value":"2294c32beb46b12cd7bc67e40eda367f6f38488594c293476b41a035694a6c81",
         "type":"String"
      },
      {
         "value":"5e13ba756a7cc3418a5c3336bf05933ef5bcf663342e348cedc86000da113ca1",
         "type":"String"
      },
      {
         "value":"38afa68be9f5a9e4caaabdd7291fce400ba064dafb3463be4e1f15c70c1a3ccf",
         "type":"String"
      },
      ...

```

## Passing Arguments

To pass in arguments, you just need to follow the **JSON-Cadence Data Interchange Format** and base64 encode each one, which you can read all about here: [JSON-Cadence Data Interchange Format | Flow Blockchain](https://developers.flow.com/cadence/json-cadence-spec).

Here’s an example: let’s say we want to run a [script to get the Node info](https://github.com/onflow/flow-core-contracts/blob/master/transactions/idTableStaking/scripts/get_node_info.cdc). You’ll see that script needs a `nodeID` argument, much like the script you want to run.

```auto
import FlowIDTableStaking from 0x8624b52f9ddcd04a

// This script gets all the info about a node and returns it

pub fun main(nodeID: String): FlowIDTableStaking.NodeInfo {
    return FlowIDTableStaking.NodeInfo(nodeID: nodeID)
}

```

Let’s use a test NodeID from the example above (which returns a list of node IDs), and generate an argument like this to add to the `arguments` list.

```auto
{
"type": "String",
"value": "2294c32beb46b12cd7bc67e40eda367f6f38488594c293476b41a035694a6c81"
}

```

Just Base64 encode the JSON type and include it in the argument array. This is the payload you would send:

```auto
{
  "script": "aW1wb3J0IEZsb3dJRFRhYmxlU3Rha2luZyBmcm9tIDB4ODYyNGI1MmY5ZGRjZDA0YQoKcHViIGZ1biBtYWluKG5vZGVJRDogU3RyaW5nKTogRmxvd0lEVGFibGVTdGFraW5nLk5vZGVJbmZvIHsKICAgIHJldHVybiBGbG93SURUYWJsZVN0YWtpbmcuTm9kZUluZm8obm9kZUlEOiBub2RlSUQpCn0=",
  "arguments": [
"ewoidHlwZSI6ICJTdHJpbmciLAoidmFsdWUiOiAiMjI5NGMzMmJlYjQ2YjEyY2Q3YmM2N2U0MGVkYTM2N2Y2ZjM4NDg4NTk0YzI5MzQ3NmI0MWEwMzU2OTRhNmM4MSIKfQ=="
	]
}

```

In shell, again that would be something like:

```auto
curl --request POST \
  --url https://rest-mainnet.onflow.org/v1/scripts \
  --header 'Content-Type: application/json' \
  --data '{
  "script": "aW1wb3J0IEZsb3dJRFRhYmxlU3Rha2luZyBmcm9tIDB4ODYyNGI1MmY5ZGRjZDA0YQoKcHViIGZ1biBtYWluKG5vZGVJRDogU3RyaW5nKTogRmxvd0lEVGFibGVTdGFraW5nLk5vZGVJbmZvIHsKICAgIHJldHVybiBGbG93SURUYWJsZVN0YWtpbmcuTm9kZUluZm8obm9kZUlEOiBub2RlSUQpCn0=",
  "arguments": [
"ewoidHlwZSI6ICJTdHJpbmciLAoidmFsdWUiOiAiMjI5NGMzMmJlYjQ2YjEyY2Q3YmM2N2U0MGVkYTM2N2Y2ZjM4NDg4NTk0YzI5MzQ3NmI0MWEwMzU2OTRhNmM4MSIKfQ=="
	]
}'

```

Here is the Base64 decoded response from that call:

```auto
{
  "value": {
    "id": "A.8624b52f9ddcd04a.FlowIDTableStaking.NodeInfo",
    "fields": [
      {
        "value": {
          "value": "2294c32beb46b12cd7bc67e40eda367f6f38488594c293476b41a035694a6c81",
          "type": "String"
        },
        "name": "id"
      },
      {
        "value": {
          "value": "5",
          "type": "UInt8"
        },
        "name": "role"
      },
      {
        "value": {
          "value": "flo9-aws-us-east-1.flonode.alchemyapi.io:3569",
          "type": "String"
        },
        "name": "networkingAddress"
      },
      {
        "value": {
          "value": "c8bec113851ce993b56276afe355eabb618d4f344abcbb529524212048cee1440105a1f5696f4c7c28076db39e92263d6e1fe4f0f97e5c807f510579cdbde452",
          "type": "String"
        },
        "name": "networkingKey"
      },
      {
        "value": {
          "value": "9475d65e36aa53d5872c3b6266733e620b1a515a7fa760c46d1c6c90346a90fc2d51948f02b15daa4969583c665c43120d66628b2e5d1216206d920c884ec96b5f3f8baa1381855afe153481a0bc56ea77ea8254b1632284e4db273798d0f913",
          "type": "String"
        },
        "name": "stakingKey"
      },
      {
        "value": {
          "value": "0.00000000",
          "type": "UFix64"
        },
        "name": "tokensStaked"
      },
      {
        "value": {
          "value": "0.00000000",
          "type": "UFix64"
        },
        "name": "tokensCommitted"
      },
      {
        "value": {
          "value": "0.00000000",
          "type": "UFix64"
        },
        "name": "tokensUnstaking"
      },
      {
        "value": {
          "value": "0.00000000",
          "type": "UFix64"
        },
        "name": "tokensUnstaked"
      },
      {
        "value": {
          "value": "0.00000000",
          "type": "UFix64"
        },
        "name": "tokensRewarded"
      },
      {
        "value": {
          "value": [],
          "type": "Array"
        },
        "name": "delegators"
      },
      {
        "value": {
          "value": "0",
          "type": "UInt32"
        },
        "name": "delegatorIDCounter"
      },
      {
        "value": {
          "value": "0.00000000",
          "type": "UFix64"
        },
        "name": "tokensRequestedToUnstake"
      },
      {
        "value": {
          "value": "100",
          "type": "UInt64"
        },
        "name": "initialWeight"
      }
    ]
  },
  "type": "Struct"
}

```

Hope you get the gist!

---

<div class="post-metadata">

**Author:** ![alextoporov](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@alextoporov](https://forum.flow.com/u/alextoporov)\
**Post date:** [March 1, 2023, 5:44am UTC](https://forum.flow.com/t/struggle-with-executing-a-cadence-script/4389/3 "2023-03-01T05:44:56Z")

</div>

Thank you so much! Now I see, it’s now very clear)
