# Create And Execute Txn

The "Create and Execute Transaction" feature in the KrypC wallet-dev Service API enables users to seamlessly generate and execute transactions on the blockchain, providing a straightforward method for interacting with digital assets and facilitating secure financial transactions.

This will allow to create a transaction and execute transactions in the network.&#x20;

## API Specification

## Create And Execute Txn API

<mark style="color:green;">`POST`</mark> `https://api.krypcore.com/api/v0/devWallet/createAndExecuteTx`

To create and execute Txn API under given instance.

#### Headers

| Name                                            | Type   | Description            |
| ----------------------------------------------- | ------ | ---------------------- |
| DappId<mark style="color:red;">\*</mark>        | String | DappId                 |
| Authorization<mark style="color:red;">\*</mark> | String | User Auth key obtained |
| SubscriptionId                                  | String | SubscriptionId         |
| ChainId                                         | String | ChainId                |

#### Request Body

| Name                                            | Type   | Description   |
| ----------------------------------------------- | ------ | ------------- |
| privateKey<mark style="color:red;">\*</mark>    | String | Private key   |
| to<mark style="color:red;">\*</mark>            | String | To Address    |
| chainId<mark style="color:red;">\*</mark>       | String | Chain ID      |
| method<mark style="color:red;">\*</mark>        | String | Method        |
| params<mark style="color:red;">\*</mark>        | String | Params        |
| isContractTxn<mark style="color:red;">\*</mark> | String | IsContractTxn |
| contractABI<mark style="color:red;">\*</mark>   | String | ContractABI   |

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

```javascript
{
    "Data": {
        "txHash": "0x1de7289389106c8cdd6b244aab2b73bab5231d79e149210b68baa536564f47cb"
    },
    "Message": "Signed and executed txn successfully",
    "Status": "SUCCESS"
}
```

{% endtab %}

{% tab title="401: Unauthorized Failure in authentication" %}

```javascript
{
    "message": "Invalid API key in request"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Key values should be given" %}

```json
{
    "message": "Internal Server Error"
}
```

{% 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 --location 'https://api.krypcore.com/api/v0/devWallet/createAndExecuteTx' \
--header 'DappId: **********' \
--header 'Authorization: **********' \
--header 'SubscriptionId: ********' \
--header 'ChainId: ********' \
--header 'Content-Type: application/json' \
--data '{
    "privateKey": "**********",
    "to": "**********",
    "chainId": 80001,
    "method": "store",
    "params": [
        {
            "type": "uint256",
            "value": "35"
        }
    ],
    "isContractTxn": true,
    "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

var myHeaders = new Headers();
myHeaders.append("DappId", "**********");
myHeaders.append("Authorization", "**********");
myHeaders.append("SubscriptionId", "********");
myHeaders.append("ChainId", "********");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "privateKey": "**********",
  "to": "**********",
  "chainId": 80001,
  "method": "store",
  "params": [
    {
      "type": "uint256",
      "value": "35"
    }
  ],
  "isContractTxn": true,
  "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\"}]"
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://api.krypcore.com/api/v0/devWallet/createAndExecuteTx", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

{% endtab %}

{% tab title="Python " %}

```python

import requests
import json

url = "https://api.krypcore.com/api/v0/devWallet/createAndExecuteTx"

payload = json.dumps({
  "privateKey": "**********",
  "to": "**********",
  "chainId": 80001,
  "method": "store",
  "params": [
    {
      "type": "uint256",
      "value": "35"
    }
  ],
  "isContractTxn": True,
  "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\"}]"
})
headers = {
  'DappId': '**********',
  'Authorization': '**********',
  'SubscriptionId': '********',
  'ChainId': '********',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}

{% tab title="Golang" %}

<pre class="language-go"><code class="lang-go">
package main

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

func main() {

  url := "https://api.krypcore.com/api/v0/devWallet/createAndExecuteTx"
  method := "POST"

  payload := strings.NewReader(`{
    "privateKey": "**********",
    "to": "**********",
    "chainId": 80001,
    "method": "store",
    "params": [
        {
            "type": "uint256",
            "value": "35"
        }
    ],
    "isContractTxn": true,
    "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\"}]"
}`)

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

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

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

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
</code></pre>

{% endtab %}
{% endtabs %}
