UNPKG

@coinbase/cdp-sdk

Version:

SDK for interacting with the Coinbase Developer Platform Wallet API

201 lines (188 loc) 8.7 kB
import { cdpApiClient } from "../../cdpApiClient.js"; /** * Lists the EVM accounts belonging to the developer's CDP Project. The response is paginated, and by default, returns 20 accounts per page. * @summary List EVM accounts */ export const listEvmAccounts = (params, options) => { return cdpApiClient({ url: `/v2/evm/accounts`, method: "GET", params }, options); }; /** * Creates a new EVM account. * @summary Create EVM account */ export const createEvmAccount = (createEvmAccountBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts`, method: "POST", headers: { "Content-Type": "application/json" }, data: createEvmAccountBody, }, options); }; /** * Gets an EVM account by its address. * @summary Get EVM account by address */ export const getEvmAccount = (address, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}`, method: "GET" }, options); }; /** * Updates an existing EVM account. Use this to update the account's name or account-level policy. * @summary Update EVM account */ export const updateEvmAccount = (address, updateEvmAccountBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}`, method: "PUT", headers: { "Content-Type": "application/json" }, data: updateEvmAccountBody, }, options); }; /** * Gets an EVM account by its name. * @summary Get EVM account by name */ export const getEvmAccountByName = (name, options) => { return cdpApiClient({ url: `/v2/evm/accounts/by-name/${name}`, method: "GET" }, options); }; /** * Signs a transaction with the given EVM account and sends it to the indicated supported network. This API handles nonce management and gas estimation, leaving the developer to provide only the minimal set of fields necessary to send the transaction. The transaction should be serialized as a hex string using [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/). The transaction must be an [EIP-1559 dynamic fee transaction](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md). **Transaction fields and API behavior** - `to` *(Required)*: The address of the contract or account to send the transaction to. - `chainId` *(Ignored)*: The value of the `chainId` field in the transaction is ignored. The transaction will be sent to the network indicated by the `network` field in the request body. - `nonce` *(Optional)*: The nonce to use for the transaction. If not provided, the API will assign a nonce to the transaction based on the current state of the account. - `maxPriorityFeePerGas` *(Optional)*: The maximum priority fee per gas to use for the transaction. If not provided, the API will estimate a value based on current network conditions. - `maxFeePerGas` *(Optional)*: The maximum fee per gas to use for the transaction. If not provided, the API will estimate a value based on current network conditions. - `gasLimit` *(Optional)*: The gas limit to use for the transaction. If not provided, the API will estimate a value based on the `to` and `data` fields of the transaction. - `value` *(Optional)*: The amount of ETH, in wei, to send with the transaction. - `data` *(Optional)*: The data to send with the transaction; only used for contract calls. - `accessList` *(Optional)*: The access list to use for the transaction. * @summary Send transaction */ export const sendEvmTransaction = (address, sendEvmTransactionBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/send/transaction`, method: "POST", headers: { "Content-Type": "application/json" }, data: sendEvmTransactionBody, }, options); }; /** * Signs a transaction with the given EVM account. The transaction should be serialized as a hex string using [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/). The transaction must be an [EIP-1559 dynamic fee transaction](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md). The developer is responsible for ensuring that the unsigned transaction is valid, as the API will not validate the transaction. * @summary Sign transaction */ export const signEvmTransaction = (address, signEvmTransactionBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/sign/transaction`, method: "POST", headers: { "Content-Type": "application/json" }, data: signEvmTransactionBody, }, options); }; /** * Signs an arbitrary 32 byte hash with the given EVM account. * @summary Sign hash */ export const signEvmHash = (address, signEvmHashBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/sign`, method: "POST", headers: { "Content-Type": "application/json" }, data: signEvmHashBody, }, options); }; /** * Signs an [EIP-191](https://eips.ethereum.org/EIPS/eip-191) message with the given EVM account. Per the specification, the message in the request body is prepended with `0x19 <0x45 (E)> <thereum Signed Message:\n" + len(message)>` before being signed. * @summary Sign EIP-191 message */ export const signEvmMessage = (address, signEvmMessageBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/sign/message`, method: "POST", headers: { "Content-Type": "application/json" }, data: signEvmMessageBody, }, options); }; /** * Signs [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data with the given EVM account. * @summary Sign EIP-712 typed data */ export const signEvmTypedData = (address, eIP712Message, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/sign/typed-data`, method: "POST", headers: { "Content-Type": "application/json" }, data: eIP712Message, }, options); }; /** * Creates an EIP-7702 delegation for an EVM EOA account, upgrading it with smart account capabilities. This endpoint: - Retrieves delegation artifacts from onchain - Signs the EIP-7702 authorization for delegation - Assembles and submits a Type 4 transaction - Creates an associated smart account object The delegation allows the EVM EOA to be used as a smart account, which enables batched transactions and gas sponsorship via paymaster. * @summary Create EIP-7702 delegation */ export const createEvmEip7702Delegation = (address, createEvmEip7702DelegationBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/eip7702/delegation`, method: "POST", headers: { "Content-Type": "application/json" }, data: createEvmEip7702DelegationBody, }, options); }; /** * Returns the EIP-7702 delegation operation. Use the delegationOperationId returned by the Create EIP-7702 delegation endpoint to poll for operation completion. * @summary Get EIP-7702 delegation operation by ID */ export const getEvmEip7702DelegationOperationById = (delegationOperationId, options) => { return cdpApiClient({ url: `/v2/evm/eip7702/delegation-operations/${delegationOperationId}`, method: "GET" }, options); }; /** * Import an existing EVM account into the developer's CDP Project. This API should be called from the [CDP SDK](https://github.com/coinbase/cdp-sdk) to ensure that the associated private key is properly encrypted. * @summary Import EVM account */ export const importEvmAccount = (importEvmAccountBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/import`, method: "POST", headers: { "Content-Type": "application/json" }, data: importEvmAccountBody, }, options); }; /** * Export an existing EVM account's private key. It is important to store the private key in a secure place after it's exported. * @summary Export EVM account */ export const exportEvmAccount = (address, exportEvmAccountBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/${address}/export`, method: "POST", headers: { "Content-Type": "application/json" }, data: exportEvmAccountBody, }, options); }; /** * Export an existing EVM account's private key by its name. It is important to store the private key in a secure place after it's exported. * @summary Export EVM account by name */ export const exportEvmAccountByName = (name, exportEvmAccountByNameBody, options) => { return cdpApiClient({ url: `/v2/evm/accounts/export/by-name/${name}`, method: "POST", headers: { "Content-Type": "application/json" }, data: exportEvmAccountByNameBody, }, options); }; //# sourceMappingURL=evm-accounts.js.map