# wallet_createSession

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://api.g.alchemy.com/v2/{apiKey}

This method is used to create a session for a given address with specified permissions.

Reference: https://www.alchemy.com/docs/wallets/api-reference/smart-wallets/wallet-api-endpoints/wallet-create-session

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| params[0] | object | Yes |  |

## Result

**createSessionResponse** (object)

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "wallet_createSession",
  "params": [
    {
      "account": "0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2",
      "chainId": "0x01",
      "key": {
        "publicKey": "0x647bbf38CD0E116d1672405aE17a775572a84e03",
        "type": "secp256k1"
      },
      "permissions": [
        {
          "type": "root"
        }
      ],
      "expirySec": 1747969653
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "sessionId": "0xcd8b2d07a6fa76f1e8a5eaa8f3a7883c",
    "chainId": "0x1",
    "signatureRequest": {
      "type": "eth_signTypedData_v4",
      "data": {
        "domain": {
          "chainId": 1,
          "verifyingContract": "0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2"
        },
        "types": {
          "DeferredAction": [
            {
              "name": "nonce",
              "type": "uint256"
            },
            {
              "name": "deadline",
              "type": "uint48"
            },
            {
              "name": "call",
              "type": "bytes"
            }
          ]
        },
        "primaryType": "DeferredAction",
        "message": {
          "nonce": "0x1030000000000000000",
          "deadline": 1747969653,
          "call": "0x1bbf564c00000000000099DE0BF6fA90dEB851E2A2df7d83000000010500000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000647bbf38cd0e116d1672405ae17a775572a84e0300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000007900000000000082B8e2012be914dFA4f62A0573eA0000000101000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000682fe675000000000000000000000000000000000000000000000000000000000000000000000000000000"
        }
      },
      "rawPayload": "0x2a8073568c8fad3edf15f70c3471a7fff18e1d57c650a501ab47f57a5c1f0e39"
    }
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://api.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "wallet_createSession",
  "params": [
    {
      "account": "0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2",
      "chainId": "0x01",
      "key": {
        "publicKey": "0x647bbf38CD0E116d1672405aE17a775572a84e03",
        "type": "secp256k1"
      },
      "permissions": [
        {
          "type": "root"
        }
      ],
      "expirySec": 1747969653
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'wallet_createSession',
    params: [
      {
        account: '0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2',
        chainId: '0x01',
        key: {publicKey: '0x647bbf38CD0E116d1672405aE17a775572a84e03', type: 'secp256k1'},
        permissions: [{type: 'root'}],
        expirySec: 1747969653
      }
    ]
  })
};

fetch('https://api.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "wallet_createSession",
    "params": [
        {
            "account": "0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2",
            "chainId": "0x01",
            "key": {
                "publicKey": "0x647bbf38CD0E116d1672405aE17a775572a84e03",
                "type": "secp256k1"
            },
            "permissions": [{ "type": "root" }],
            "expirySec": 1747969653
        }
    ]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

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

func main() {

	url := "https://api.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"wallet_createSession\",\n  \"params\": [\n    {\n      \"account\": \"0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2\",\n      \"chainId\": \"0x01\",\n      \"key\": {\n        \"publicKey\": \"0x647bbf38CD0E116d1672405aE17a775572a84e03\",\n        \"type\": \"secp256k1\"\n      },\n      \"permissions\": [\n        {\n          \"type\": \"root\"\n        }\n      ],\n      \"expirySec\": 1747969653\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://api.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"wallet_createSession\",\n  \"params\": [\n    {\n      \"account\": \"0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2\",\n      \"chainId\": \"0x01\",\n      \"key\": {\n        \"publicKey\": \"0x647bbf38CD0E116d1672405aE17a775572a84e03\",\n        \"type\": \"secp256k1\"\n      },\n      \"permissions\": [\n        {\n          \"type\": \"root\"\n        }\n      ],\n      \"expirySec\": 1747969653\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://api.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"wallet_createSession\",\n  \"params\": [\n    {\n      \"account\": \"0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2\",\n      \"chainId\": \"0x01\",\n      \"key\": {\n        \"publicKey\": \"0x647bbf38CD0E116d1672405aE17a775572a84e03\",\n        \"type\": \"secp256k1\"\n      },\n      \"permissions\": [\n        {\n          \"type\": \"root\"\n        }\n      ],\n      \"expirySec\": 1747969653\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: wallet_createSession
description: This method is used to create a session for a given address with specified permissions.
params:
  - name: params[0]
    required: true
    schema:
      type: object
      required:
        - account
        - chainId
        - key
        - permissions
      properties:
        chainId:
          type: string
          pattern: ^0x.*$
          errorMessage: Must be a valid hex string starting with '0x'
        expirySec:
          type: integer
          maximum: 9999999999
          description: Unix timestamp in seconds (0 for no expiry)
        key:
          type: object
          required:
            - type
            - publicKey
          properties:
            type:
              anyOf:
                - type: string
                  description: Secp256k1
                  enum:
                    - secp256k1
                - type: string
                  description: ECDSA (alias for secp256k1)
                  enum:
                    - ecdsa
                - type: string
                  description: Contract
                  enum:
                    - contract
            publicKey:
              type: string
              pattern: ^0x.*$
              errorMessage: Must be a valid hex string starting with '0x'
              description: Note that this should be the public key's 20-byte address, not the full 64-byte public key
        permissions:
          type: array
          minItems: 1
          items:
            anyOf:
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - native-token-transfer
                  data:
                    type: object
                    required:
                      - allowance
                    properties:
                      allowance:
                        type: string
                        pattern: ^0x.*$
                        errorMessage: Must be a valid hex string starting with '0x'
                description: allows transfer of native tokens from the account
                title: native-token-transfer
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - erc20-token-transfer
                  data:
                    type: object
                    required:
                      - allowance
                      - address
                    properties:
                      allowance:
                        type: string
                        pattern: ^0x.*$
                        errorMessage: Must be a valid hex string starting with '0x'
                      address:
                        type: string
                        pattern: ^0x.*$
                        errorMessage: Must be a valid Ethereum address starting with '0x' (e.g., '0xa363219d7C0b8673df17529D469Db9eFF0f35D2A')
                description: allows transfer or approval of erc20 tokens from the account
                title: erc20-token-transfer
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - gas-limit
                  data:
                    type: object
                    required:
                      - limit
                    properties:
                      limit:
                        type: string
                        pattern: ^0x.*$
                        errorMessage: Must be a valid hex string starting with '0x'
                description: allows the key to spend gas for UOs
                title: gas-limit
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - contract-access
                  data:
                    type: object
                    required:
                      - address
                    properties:
                      address:
                        type: string
                        pattern: ^0x.*$
                        errorMessage: Must be a valid Ethereum address starting with '0x' (e.g., '0xa363219d7C0b8673df17529D469Db9eFF0f35D2A')
                description: grants access to all functions in a contract
                title: contract-access
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - account-functions
                  data:
                    type: object
                    required:
                      - functions
                    properties:
                      functions:
                        type: array
                        minItems: 1
                        items:
                          type: string
                          pattern: ^0x.*$
                          errorMessage: Must be a valid hex string starting with '0x'
                description: grants access to functions in the account
                title: account-functions
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - functions-on-all-contracts
                  data:
                    type: object
                    required:
                      - functions
                    properties:
                      functions:
                        type: array
                        minItems: 1
                        items:
                          type: string
                          pattern: ^0x.*$
                          errorMessage: Must be a valid hex string starting with '0x'
                description: access to a function selector in any address or contract
                title: functions-on-all-contracts
              - type: object
                required:
                  - type
                  - data
                properties:
                  type:
                    type: string
                    enum:
                      - functions-on-contract
                  data:
                    type: object
                    required:
                      - address
                      - functions
                    properties:
                      address:
                        type: string
                        pattern: ^0x.*$
                        errorMessage: Must be a valid Ethereum address starting with '0x' (e.g., '0xa363219d7C0b8673df17529D469Db9eFF0f35D2A')
                      functions:
                        type: array
                        minItems: 1
                        items:
                          type: string
                          pattern: ^0x.*$
                          errorMessage: Must be a valid hex string starting with '0x'
                description: grants access to specified functions on a specific contract
                title: functions-on-contract
              - type: object
                required:
                  - type
                properties:
                  type:
                    type: string
                    enum:
                      - root
                description: grants full access to everything
                title: root
        account:
          type: string
          pattern: ^0x.*$
          errorMessage: Must be a valid Ethereum address starting with '0x' (e.g., '0xa363219d7C0b8673df17529D469Db9eFF0f35D2A')
result:
  name: createSessionResponse
  schema:
    type: object
    required:
      - sessionId
      - chainId
      - signatureRequest
    properties:
      sessionId:
        type: string
        pattern: ^0x.*$
        errorMessage: Must be a valid hex string starting with '0x'
      chainId:
        type: string
        pattern: ^0x.*$
        errorMessage: Must be a valid hex string starting with '0x'
      signatureRequest:
        type: object
        required:
          - type
          - data
          - rawPayload
        description: Typed data
        properties:
          type:
            type: string
            enum:
              - eth_signTypedData_v4
          data:
            type: object
            required:
              - types
              - primaryType
              - message
            properties:
              domain:
                type: object
                properties:
                  chainId:
                    type: integer
                  name:
                    type: string
                  salt:
                    type: string
                    pattern: ^0x.*$
                    errorMessage: Must be a valid hex string starting with '0x'
                  verifyingContract:
                    type: string
                    pattern: ^0x.*$
                    errorMessage: Must be a valid Ethereum address starting with '0x' (e.g., '0xa363219d7C0b8673df17529D469Db9eFF0f35D2A')
                  version:
                    type: string
              types:
                type: object
                description: Mapping from type name to array of field definitions
                additionalProperties:
                  type: array
                  items:
                    type: object
                    required:
                      - name
                      - type
                    properties:
                      name:
                        type: string
                      type:
                        type: string
              primaryType:
                type: string
              message:
                type: object
                description: Mapping from field name to value
          rawPayload:
            type: string
            pattern: ^0x.*$
            errorMessage: Must be a valid hex string starting with '0x'
            description: Raw payload that can be signed if using a signer that supports signing raw bytes (such as an Alchemy Signer)
examples:
  - name: wallet_createSession example
    params:
      - name: param0
        value:
          account: '0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2'
          chainId: '0x01'
          key:
            publicKey: '0x647bbf38CD0E116d1672405aE17a775572a84e03'
            type: secp256k1
          permissions:
            - type: root
          expirySec: 1747969653
    result:
      name: Response
      value:
        sessionId: '0xcd8b2d07a6fa76f1e8a5eaa8f3a7883c'
        chainId: '0x1'
        signatureRequest:
          type: eth_signTypedData_v4
          data:
            domain:
              chainId: 1
              verifyingContract: '0xafdABa1E09e82F780721963eba39bA9e6d9FE4d2'
            types:
              DeferredAction:
                - name: nonce
                  type: uint256
                - name: deadline
                  type: uint48
                - name: call
                  type: bytes
            primaryType: DeferredAction
            message:
              nonce: '0x1030000000000000000'
              deadline: 1747969653
              call: '0x1bbf564c00000000000099DE0BF6fA90dEB851E2A2df7d83000000010500000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000647bbf38cd0e116d1672405ae17a775572a84e0300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000007900000000000082B8e2012be914dFA4f62A0573eA0000000101000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000682fe675000000000000000000000000000000000000000000000000000000000000000000000000000000'
          rawPayload: '0x2a8073568c8fad3edf15f70c3471a7fff18e1d57c650a501ab47f57a5c1f0e39'
```
