The namespace containing all Policy methods.

Implements

Constructors

Methods

  • Creates a new policy that can be used to govern the behavior of projects and accounts.

    Parameters

    • options: CreatePolicyOptions

      Options for creating the policy

      Options for creating a Policy.

      • OptionalidempotencyKey?: string

        The idempotency key to ensure the request is processed exactly once. Used to safely retry requests without accidentally performing the same operation twice.

      • policy: {
            description?: string;
            rules: (
                | {
                    action: "reject"
                    | "accept";
                    criteria: (
                        | {
                            ethValue: string;
                            operator: ">"
                            | ">="
                            | "<"
                            | "<="
                            | "==";
                            type: "ethValue";
                        }
                        | {
                            addresses: `0x${string}`[];
                            operator: "in"
                            | "not in";
                            type: "evmAddress";
                        }
                        | {
                            abi: | "erc20"
                            | "erc721"
                            | "erc1155"
                            | readonly (
                                | { inputs: ...; name: ...; type: ... }
                                | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                                | (
                                    { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                                )
                            )[];
                            conditions: { function: string; params?: (...)[] }[];
                            type: "evmData";
                        }
                    )[];
                    operation: "signEvmTransaction";
                }
                | { action: "reject"
                | "accept"; operation: "signEvmHash" }
                | {
                    action: "reject" | "accept";
                    criteria: { match: string; type: "evmMessage" }[];
                    operation: "signEvmMessage";
                }
                | {
                    action: "reject"
                    | "accept";
                    criteria: (
                        | {
                            ethValue: string;
                            operator: ">"
                            | ">="
                            | "<"
                            | "<="
                            | "==";
                            type: "ethValue";
                        }
                        | {
                            addresses: `0x${string}`[];
                            operator: "in"
                            | "not in";
                            type: "evmAddress";
                        }
                        | {
                            networks: ("base-sepolia" | "base")[];
                            operator: "in" | "not in";
                            type: "evmNetwork";
                        }
                        | {
                            abi: | "erc20"
                            | "erc721"
                            | "erc1155"
                            | readonly (
                                | { inputs: ...; name: ...; type: ... }
                                | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                                | (
                                    { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                                )
                            )[];
                            conditions: { function: string; params?: (...)[] }[];
                            type: "evmData";
                        }
                    )[];
                    operation: "sendEvmTransaction";
                }
                | {
                    action: "reject"
                    | "accept";
                    criteria: {
                        addresses: string[];
                        operator: "in" | "not in";
                        type: "solAddress";
                    }[];
                    operation: "signSolTransaction";
                }
            )[];
            scope: "project"
            | "account";
        }

        The policy definition to create. Contains the scope, description, and rules for the policy.

        • Optionaldescription?: string

          An optional human-readable description for the policy. Limited to 50 characters of alphanumeric characters, spaces, commas, and periods.

        • rules: (
              | {
                  action: "reject"
                  | "accept";
                  criteria: (
                      | {
                          ethValue: string;
                          operator: ">"
                          | ">="
                          | "<"
                          | "<="
                          | "==";
                          type: "ethValue";
                      }
                      | {
                          addresses: `0x${string}`[];
                          operator: "in"
                          | "not in";
                          type: "evmAddress";
                      }
                      | {
                          abi: | "erc20"
                          | "erc721"
                          | "erc1155"
                          | readonly (
                              | { inputs: ...; name: ...; type: ... }
                              | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                              | (
                                  { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                              )
                          )[];
                          conditions: { function: string; params?: (...)[] }[];
                          type: "evmData";
                      }
                  )[];
                  operation: "signEvmTransaction";
              }
              | { action: "reject"
              | "accept"; operation: "signEvmHash" }
              | {
                  action: "reject" | "accept";
                  criteria: { match: string; type: "evmMessage" }[];
                  operation: "signEvmMessage";
              }
              | {
                  action: "reject"
                  | "accept";
                  criteria: (
                      | {
                          ethValue: string;
                          operator: ">"
                          | ">="
                          | "<"
                          | "<="
                          | "==";
                          type: "ethValue";
                      }
                      | {
                          addresses: `0x${string}`[];
                          operator: "in"
                          | "not in";
                          type: "evmAddress";
                      }
                      | {
                          networks: ("base-sepolia" | "base")[];
                          operator: "in" | "not in";
                          type: "evmNetwork";
                      }
                      | {
                          abi: | "erc20"
                          | "erc721"
                          | "erc1155"
                          | readonly (
                              | { inputs: ...; name: ...; type: ... }
                              | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                              | (
                                  { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                              )
                          )[];
                          conditions: { function: string; params?: (...)[] }[];
                          type: "evmData";
                      }
                  )[];
                  operation: "sendEvmTransaction";
              }
              | {
                  action: "reject"
                  | "accept";
                  criteria: {
                      addresses: string[];
                      operator: "in" | "not in";
                      type: "solAddress";
                  }[];
                  operation: "signSolTransaction";
              }
          )[]

          Array of rules that comprise the policy. Limited to a maximum of 10 rules per policy.

        • scope: "project" | "account"

          The scope of the policy. "project" applies to the entire project, "account" applies to specific accounts.

    Returns Promise<Policy>

    The created policy

    When the policy is invalid

             const policy = await cdp.policies.createPolicy({
    policy: {
    scope: "account",
    description: "Limits the amount of ETH in transaction",
    rules: [
    {
    action: "reject",
    operation: "signEvmTransaction",
    criteria: [
    {
    type: "ethValue",
    ethValue: "1000000000000000000",
    operator: ">",
    },
    ],
    },
    ],
    }
    });
             const idempotencyKey = uuidv4();

    // First call creates the policy
    const policy = await cdp.policies.createPolicy({
    policy: {
    scope: "account",
    description: "Limits the amount of ETH in transaction",
    rules: [
    {
    action: "reject",
    operation: "signEvmTransaction",
    criteria: [
    {
    type: "ethValue",
    ethValue: "1000000000000000000",
    operator: ">",
    },
    ],
    },
    ],
    },
    idempotencyKey
    });

    // Second call with same key returns the same policy
    const samePolicy = await cdp.policies.createPolicy({
    policy: { ... },
    idempotencyKey
    });
  • Deletes a policy by its unique identifier. If a policy is referenced by an active project or account, this operation will fail.

    Parameters

    • options: DeletePolicyOptions

      Options containing the policy ID to delete

      Options for deleting a Policy.

      • id: string

        The unique identifier of the policy to delete. This is a UUID that's generated when the policy is created.

      • OptionalidempotencyKey?: string

        The idempotency key to ensure the request is processed exactly once. Used to safely retry requests without accidentally performing the same operation twice.

    Returns Promise<void>

    Void on successful deletion

             await cdp.policies.deletePolicy({
    id: "__ID__"
    });
             const idempotencyKey = uuidv4();

    // This operation is idempotent with the key
    await cdp.policies.deletePolicy({
    id: "__ID__",
    idempotencyKey
    });
  • Retrieves a policy by its unique identifier.

    Parameters

    • options: GetPolicyByIdOptions

      Options containing the policy ID to retrieve

      Options for retrieving a Policy by ID.

      • id: string

        The unique identifier of the policy to retrieve. This is a UUID that's generated when the policy is created.

    Returns Promise<Policy>

    The requested policy

             const policy = await cdp.policies.getPolicyById({
    id: "__ID__"
    });

    console.log(policy.name);
    console.log(policy.rules);
  • Lists policies belonging to the developer's CDP Project. Can be filtered by scope (project or account).

    Parameters

    • Optionaloptions: ListPoliciesOptions = {}

      Options for filtering and paginating the results

      • OptionalpageSize?: number

        The page size to paginate through the accounts.

      • OptionalpageToken?: string

        The page token to paginate through the accounts.

      • Optionalscope?: "project" | "account"

        The scope of the policies to return. If project, the response will include exactly one policy, which is the project-level policy. If account, the response will include all account-level policies for the developer's CDP Project.

    Returns Promise<ListPoliciesResult>

    A paginated list of policies

             const { policies } = await cdp.policies.listPolicies();
             const { policies } = await cdp.policies.listPolicies({
    scope: 'project'
    });
             // Get first page
    const firstPage = await cdp.policies.listPolicies({
    pageSize: 10
    });

    // Get next page using cursor
    const nextPage = await cdp.policies.listPolicies({
    pageSize: 10,
    pageToken: firstPage.pageToken
    });
  • Updates an existing policy by its unique identifier. This will apply the updated policy to any project or accounts that are currently using it.

    Parameters

    • options: UpdatePolicyOptions

      Options containing the policy ID and updated policy data

      Options for updating a Policy.

      • id: string

        The unique identifier of the policy to update. This is a UUID that's generated when the policy is created.

      • OptionalidempotencyKey?: string

        The idempotency key to ensure the request is processed exactly once. Used to safely retry requests without accidentally performing the same operation twice.

      • policy: {
            description?: string;
            rules: (
                | {
                    action: "reject"
                    | "accept";
                    criteria: (
                        | {
                            ethValue: string;
                            operator: ">"
                            | ">="
                            | "<"
                            | "<="
                            | "==";
                            type: "ethValue";
                        }
                        | {
                            addresses: `0x${string}`[];
                            operator: "in"
                            | "not in";
                            type: "evmAddress";
                        }
                        | {
                            abi: | "erc20"
                            | "erc721"
                            | "erc1155"
                            | readonly (
                                | { inputs: ...; name: ...; type: ... }
                                | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                                | (
                                    { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                                )
                            )[];
                            conditions: { function: string; params?: (...)[] }[];
                            type: "evmData";
                        }
                    )[];
                    operation: "signEvmTransaction";
                }
                | { action: "reject"
                | "accept"; operation: "signEvmHash" }
                | {
                    action: "reject" | "accept";
                    criteria: { match: string; type: "evmMessage" }[];
                    operation: "signEvmMessage";
                }
                | {
                    action: "reject"
                    | "accept";
                    criteria: (
                        | {
                            ethValue: string;
                            operator: ">"
                            | ">="
                            | "<"
                            | "<="
                            | "==";
                            type: "ethValue";
                        }
                        | {
                            addresses: `0x${string}`[];
                            operator: "in"
                            | "not in";
                            type: "evmAddress";
                        }
                        | {
                            networks: ("base-sepolia" | "base")[];
                            operator: "in" | "not in";
                            type: "evmNetwork";
                        }
                        | {
                            abi: | "erc20"
                            | "erc721"
                            | "erc1155"
                            | readonly (
                                | { inputs: ...; name: ...; type: ... }
                                | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                                | (
                                    { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                                )
                            )[];
                            conditions: { function: string; params?: (...)[] }[];
                            type: "evmData";
                        }
                    )[];
                    operation: "sendEvmTransaction";
                }
                | {
                    action: "reject"
                    | "accept";
                    criteria: {
                        addresses: string[];
                        operator: "in" | "not in";
                        type: "solAddress";
                    }[];
                    operation: "signSolTransaction";
                }
            )[];
        }

        The updated policy definition. Contains the description and rules for the policy.

        • Optionaldescription?: string

          An optional human-readable description for the policy. Limited to 50 characters of alphanumeric characters, spaces, commas, and periods.

        • rules: (
              | {
                  action: "reject"
                  | "accept";
                  criteria: (
                      | {
                          ethValue: string;
                          operator: ">"
                          | ">="
                          | "<"
                          | "<="
                          | "==";
                          type: "ethValue";
                      }
                      | {
                          addresses: `0x${string}`[];
                          operator: "in"
                          | "not in";
                          type: "evmAddress";
                      }
                      | {
                          abi: | "erc20"
                          | "erc721"
                          | "erc1155"
                          | readonly (
                              | { inputs: ...; name: ...; type: ... }
                              | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                              | (
                                  { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                              )
                          )[];
                          conditions: { function: string; params?: (...)[] }[];
                          type: "evmData";
                      }
                  )[];
                  operation: "signEvmTransaction";
              }
              | { action: "reject"
              | "accept"; operation: "signEvmHash" }
              | {
                  action: "reject" | "accept";
                  criteria: { match: string; type: "evmMessage" }[];
                  operation: "signEvmMessage";
              }
              | {
                  action: "reject"
                  | "accept";
                  criteria: (
                      | {
                          ethValue: string;
                          operator: ">"
                          | ">="
                          | "<"
                          | "<="
                          | "==";
                          type: "ethValue";
                      }
                      | {
                          addresses: `0x${string}`[];
                          operator: "in"
                          | "not in";
                          type: "evmAddress";
                      }
                      | {
                          networks: ("base-sepolia" | "base")[];
                          operator: "in" | "not in";
                          type: "evmNetwork";
                      }
                      | {
                          abi: | "erc20"
                          | "erc721"
                          | "erc1155"
                          | readonly (
                              | { inputs: ...; name: ...; type: ... }
                              | { anonymous?: ...; inputs: ...; name: ...; type: ... }
                              | (
                                  { payable?: boolean | undefined; constant?: boolean | undefined; gas?: number | undefined; } & ({ inputs: readonly AbiParameter[]; outputs: readonly AbiParameter[]; type: "function"; name: string; stateMutability: "pure" | ... 2 more ... | "payable"; } | { ...; } | { ...; } | { ...; })
                              )
                          )[];
                          conditions: { function: string; params?: (...)[] }[];
                          type: "evmData";
                      }
                  )[];
                  operation: "sendEvmTransaction";
              }
              | {
                  action: "reject"
                  | "accept";
                  criteria: {
                      addresses: string[];
                      operator: "in" | "not in";
                      type: "solAddress";
                  }[];
                  operation: "signSolTransaction";
              }
          )[]

          Array of rules that comprise the policy. Limited to a maximum of 10 rules per policy.

    Returns Promise<Policy>

    The updated policy

    When the updated policy is invalid

             const updatedPolicy = await cdp.policies.updatePolicy({
    id: "__ID__",
    policy: {
    description: "Now with lower transaction limits",
    rules: [
    {
    action: "reject",
    operation: "signEvmTransaction",
    criteria: [
    {
    type: "ethValue",
    ethValue: "1000000000",
    operator: ">",
    },
    ],
    },
    ],
    },
    });
             const idempotencyKey = uuidv4();

    // This operation is idempotent with the key
    await cdp.policies.updatePolicy({
    id: "__ID__",
    policy: {
    description: "Modified Policy",
    rules: { ... }
    },
    idempotencyKey
    });