# Call Contract Method

This Call Contract Method using this method.&#x20;

## API Specification

## Call Contract Method

<mark style="color:green;">`POST`</mark> `http://localhost:8889/wallet/callContract`

Call Contract Method under the given instance.&#x20;

**Headers**

| Name      | Type   | Description |
| --------- | ------ | ----------- |
| ChainId\* | String | ChainId     |

#### Request Body

| Name                                          | Type   | Description                                            |
| --------------------------------------------- | ------ | ------------------------------------------------------ |
| to<mark style="color:red;">\*</mark>          | String | The recipient's address                                |
| walletId<mark style="color:red;">\*</mark>    | String | The ID of the wallet                                   |
| params<mark style="color:red;">\*</mark>      | String | Additional parameters for the transaction              |
| method<mark style="color:red;">\*</mark>      | String | The method for the transaction                         |
| contractABI<mark style="color:red;">\*</mark> | String | The Application Binary Interface (ABI) of the contract |

{% tabs %}
{% tab title="200: OK SUCCESS" %}

```javascript
{
  "Status": "SUCCESS",
  "Message": "",
  "Data": {
    "response": []
  }
}
```

{% endtab %}

{% tab title="417: Expectation Failed invalid contract abi" %}

```javascript
{
    "Status": "FAILURE",
    "Message": "error reading ABI : EOF",
    "Data": null
}
```

{% endtab %}

{% tab title="401: Unauthorized invalid wallet id" %}

```javascript
{
    "Status": "FAILURE",
    "Message": "Key not found",
    "Data": null
}
```

{% endtab %}
{% endtabs %}

Take a look at how you might call this method using our official libraries, or via `curl`:

{% tabs %}
{% tab title="curl" %}

```bash
curl -X POST http://localhost:8889/wallet/callContract \
-H "Content-Type: application/json" \
-H "ChainId: xxxx" \
-d '{
  "walletId": "effae2b6-3ee3-48cb-9528-87c29152c89e",
  "to": "0xc2de797fab7d2d2b26246e93fcf2cd5873a90b10",
  "method": "store",
  "params": [
    {
      "type": "uint256",
      "value": "35"
    }
  ],
  "contractABI": "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"store\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"retrieve\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"
}'

```

{% endtab %}

{% tab title="Node.js (Fetch)" %}

```javascript
const axios = require('axios');

const data = JSON.stringify({
  walletId: 'effae2b6-3ee3-48cb-9528-87c29152c89e',
  to: '0xc2de797fab7d2d2b26246e93fcf2cd5873a90b10',
  method: 'store',
  params: [{ type: 'uint256', value: '35' }],
  contractABI: '[{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]'
});

const config = {
  method: 'post',
  url: 'http://localhost:8889/wallet/callContract',
  headers: {
    'Content-Type': 'application/json',
    'ChainId': 'xxxx',
  },
  data: data,
};

axios(config)
  .then(function (response) {
    console.log(JSON.stringify(response.data));
  })
  .catch(function (error) {
    console.log(error);
  });

```

{% endtab %}

{% tab title="Python " %}

```python
import requests
import json

url = 'http://localhost:8889/wallet/callContract'
headers = {
    'Content-Type': 'application/json',
    'ChainId': 'xxxx' \
}
data = {
    "walletId": "effae2b6-3ee3-48cb-9528-87c29152c89e",
    "to": "0xc2de797fab7d2d2b26246e93fcf2cd5873a90b10",
    "method": "store",
    "params": [{"type": "uint256", "value": "35"}],
    "contractABI": "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"store\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"retrieve\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

print(response.json())

```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "http://localhost:8889/wallet/callContract"
  method := "POST"

  payload := strings.NewReader(`{
  "walletId": "effae2b6-3ee3-48cb-9528-87c29152c89e",
  "to": "0xc2de797fab7d2d2b26246e93fcf2cd5873a90b10",
  "method": "store",
  "params": [
    {
      "type": "uint256",
      "value": "35"
    }
  ],
  "contractABI": "[]"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("ChainId", "xxxxxx")
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.krypcore.com/dev-docs/api-reference/core-service-apis/wallet-manager/self-managed-wallet/call-contract-method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
