Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 9 additions & 41 deletions fern/wallets/pages/transactions/cross-chain-swap-tokens/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,14 @@ You will need to fill in values wrapped in curly braces like `{SIGNER_ADDRESS}`.

<Steps>

<Step title="Request an account">

```bash
curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "wallet_requestAccount",
"params": [
{
"signerAddress": "{SIGNER_ADDRESS}"
}
]
}'
```

This returns:

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"accountAddress": "ACCOUNT_ADDRESS",
"id": "ACCOUNT_ID"
}
}
```

For other potential responses, [check out the API reference!](/docs/wallets/api-reference/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/wallet-request-account)

</Step>

<Step title="Request a cross-chain swap quote">

<Info>
**Important**: Cross-chain swaps do not support `postCalls`. You cannot batch
additional actions after a cross-chain swap.
</Info>

Request a cross-chain swap quote by specifying both the source chain (`chainId`) and destination chain (`toChainId`). In addition, just like in [single-chain swaps](/wallets/transactions/swap-tokens) you can specify either a `minimumToAmount` or a `fromAmount`.
Use your signer address directly as the `from` field to enable [EIP-7702](/wallets/transactions/using-eip-7702) by default. Request a cross-chain swap quote by specifying both the source chain (`chainId`) and destination chain (`toChainId`). In addition, just like in [single-chain swaps](/wallets/transactions/swap-tokens) you can specify either a `minimumToAmount` or a `fromAmount`.

<Info>
If you're using an EOA or just want the raw array of calls returned, pass the
Expand All @@ -59,7 +25,7 @@ curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
"method": "wallet_requestQuote_v0",
"params": [
{
"from": "{ACCOUNT_ADDRESS_FROM_STEP_1}",
"from": "{SIGNER_ADDRESS}",
"chainId": "{SOURCE_CHAIN_ID}",
"toChainId": "{DESTINATION_CHAIN_ID}",
"fromToken": "{FROM_TOKEN}",
Expand Down Expand Up @@ -110,6 +76,8 @@ This returns:

Note the `callId` in the response! You'll use this to track the cross-chain swap status. Also note the `signatureRequest` - this is what you need to sign, and the returned `data` field is what you'll need to send the transaction.

On the first transaction for a new account, the response type will be `array` containing both an EIP-7702 authorization and a user operation. See [Send Transactions](/wallets/transactions/send-transactions) for handling first-time authorization signing.

</Step>

<Step title="Sign the signature request">
Expand All @@ -124,7 +92,7 @@ Alternatively, you can sign the raw payload with a simple `eth_sign` but this RP

<Step title="Send the prepared call">

Pass the `callId` from Step 2 to `sendPreparedCalls`. This makes the response return the same `callId` with additional cross-chain status tracking information:
Pass the `callId` from Step 1 to `sendPreparedCalls`. This makes the response return the same `callId` with additional cross-chain status tracking information:

```bash
curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
Expand All @@ -134,13 +102,13 @@ curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
"method": "wallet_sendPreparedCalls",
"params": [
{
"callId": "{CALL_ID_FROM_STEP_2}",
"callId": "{CALL_ID_FROM_STEP_1}",
"type": "user-operation-v070",
"data": "{DATA_FROM_STEP_2}",
"data": "{DATA_FROM_STEP_1}",
"chainId": "{SOURCE_CHAIN_ID}",
"signature": {
"type": "secp256k1",
"data": "{SIGNATURE_FROM_STEP_3}"
"data": "{SIGNATURE_FROM_STEP_2}"
}
}
],
Expand Down Expand Up @@ -178,7 +146,7 @@ curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
"method": "wallet_getCallsStatus",
"params": [
[
"{CALL_ID_FROM_STEP_2_OR_STEP_4}"
"{CALL_ID_FROM_STEP_1_OR_STEP_3}"
]
],
"id": 1
Expand Down
27 changes: 9 additions & 18 deletions fern/wallets/pages/transactions/cross-chain-swap-tokens/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ You'll need the following env variables:
<CodeBlocks>
```ts title="requestCrossChainQuote.ts"
import { swapActions } from "@account-kit/wallet-client/experimental";
import { client } from "./client";

const account = await client.requestAccount();
import { client, signer } from "./client";

// Add the swap actions to the client
const swapClient = client.extend(swapActions);

// Request the cross-chain swap quote
// Note: toChainId specifies the destination chain for the swap
const { quote, callId, ...calls } = await swapClient.requestQuoteV0({
from: account.address,
from: await signer.getAddress(), // Your wallet address
toChainId: "0x...", // Destination chain ID
fromToken: "0x...",
toToken: "0x...",
Expand Down Expand Up @@ -83,24 +81,17 @@ You'll need the following env variables:
import { alchemy, sepolia } from "@account-kit/infra";
import { createSmartWalletClient } from "@account-kit/wallet-client";

const clientParams = {
export const signer = LocalAccountSigner.privateKeyToAccountSigner(
process.env.PRIVATE_KEY! as Hex,
)

export const client = createSmartWalletClient({
transport: alchemy({
apiKey: process.env.ALCHEMY_API_KEY!,
}),
chain: sepolia,
signer: LocalAccountSigner.privateKeyToAccountSigner(
process.env.PRIVATE_KEY! as Hex,
),
signer,
policyId: process.env.ALCHEMY_POLICY_ID!, // Optional: If you're using a gas manager policy
};

const clientWithoutAccount = createSmartWalletClient(clientParams);

const account = await clientWithoutAccount.requestAccount();

export const client = createSmartWalletClient({
...clientParams,
account: account.address,
});
```
```
</CodeBlocks>
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,8 @@ reference](/wallets/api/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/
for full descriptions of the parameters used in the following example.

<Steps>
<Step title="(If Needed) Request Account">
If the user does not yet have a smart account, you must create one.
```bash
ACCOUNT_ADDRESS=$(curl --request POST \
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
--header 'accept: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "wallet_requestAccount",
"params": [
{
"signerAddress": "'$SIGNER_ADDRESS'"
}
]
}
' | jq -r '.result.accountAddress')
```
</Step>
<Step title="Prepare Calls">
Prepare calls using the `paymasterService` capability.
Prepare calls using the `paymasterService` capability. Use your signer address directly as the `from` field to enable [EIP-7702](/wallets/transactions/using-eip-7702) by default.
```bash
curl --request POST \
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
Expand Down Expand Up @@ -55,14 +35,14 @@ curl --request POST \
"to": "0x0000000000000000000000000000000000000000"
}
],
"from": "'$ACCOUNT_ADDRESS'",
"from": "'$SIGNER_ADDRESS'",
"chainId": "'$CHAIN_ID'"
}
]
}'
```
</Step>
<Step title="Sign & Send">
Sign the returned signature request and send using `wallet_sendPreparedCalls`. See the [send transactions guide](/wallets/transactions/send-transactions) for more info.
Sign the returned signature request and send using `wallet_sendPreparedCalls`. On the first transaction for a new account, the response type will be `array` containing both an EIP-7702 authorization and a user operation. See the [send transactions guide](/wallets/transactions/send-transactions) for a complete example.
</Step>
</Steps>
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
<Steps>
<Step title="(If Needed) Request Account">
If the user does not yet have a smart account, you must create one.

```bash
ACCOUNT_ADDRESS=$(curl --request POST \
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
--header 'accept: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "wallet_requestAccount",
"params": [
{
"signerAddress": "'$SIGNER_ADDRESS'"
}
]
}
' | jq -r '.result.accountAddress')
```
</Step>

<Step title="Initial Prepare Calls">
Prepare calls using the `paymasterService` capability.
Prepare calls using the `paymasterService` capability. Use your signer address directly as the `from` field to enable [EIP-7702](/wallets/transactions/using-eip-7702) by default.

```bash
curl --request POST \
Expand Down Expand Up @@ -54,7 +32,7 @@
"to": "0x0000000000000000000000000000000000000000"
}
],
"from": "'$ACCOUNT_ADDRESS'",
"from": "'$SIGNER_ADDRESS'",
"chainId": "'$CHAIN_ID'"
}
]
Expand All @@ -63,7 +41,7 @@
</Step>

<Step title="(If Needed) Sign Permit Request">
If the response to step 2 is a type `paymaster-permit`, then the user must sign the signature request and return via a second call to `wallet_prepareCalls`. Else, skip to step 5.
If the response to step 1 is a type `paymaster-permit`, then the user must sign the signature request and return via a second call to `wallet_prepareCalls`. Else, skip to step 4.
The `data` field on the `paymaster-permit` response contains a [Permit typed message](https://eips.ethereum.org/EIPS/eip-2612). It is recommended that the user
checks the fields of this message prior to calculating its hash. The `signatureRequest` field on the `paymaster-permit` response is a required signature over the calculated
hash. This is typically an ERC-712 typed signature envelope with a field for the hash to sign over.
Expand All @@ -72,7 +50,7 @@
<Step title="(If Needed) Second Prepare Calls">
After signing, another call to `wallet_prepareCalls` is needed to encode the permit into the operation. As a convenience, the `paymaster-permit` response type returns a `modifiedRequest`
parameter that modifies the initial request with the permit details. The second request is the `modifiedRequest` with an additional `paymasterPermitSignature` field set to the
signature from step 3. The user can also choose to recreate the request and set the corresponding fields in the `paymasterService` capability to the details returned in the permit signature.
signature from step 2. The user can also choose to recreate the request and set the corresponding fields in the `paymasterService` capability to the details returned in the permit signature.
For example:

```json
Expand All @@ -89,13 +67,13 @@
}
}
}
... // same request as step 2
... // same request as step 1
"paymasterPermitSignature": "0x..."
}
```
</Step>

<Step title="Sign & Send">
Sign and send the last prepared calls result as usual using `wallet_sendPreparedCalls`. See the [send transactions guide](/wallets/transactions/send-transactions) for more info.
Sign and send the last prepared calls result as usual using `wallet_sendPreparedCalls`. On the first transaction for a new account, the response type will be `array` containing both an EIP-7702 authorization and a user operation. See the [send transactions guide](/wallets/transactions/send-transactions) for a complete example.
</Step>
</Steps>
19 changes: 6 additions & 13 deletions fern/wallets/pages/transactions/pay-gas-with-any-token/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,16 @@ export const config = {
approveAmount: toHex(10000000n), // 10 USDC
};

const clientParams = {
export const signer = LocalAccountSigner.privateKeyToAccountSigner(
process.env.PRIVATE_KEY! as Hex,
);

export const client = createSmartWalletClient({
transport: alchemy({
apiKey: process.env.ALCHEMY_API_KEY!,
}),
chain: sepolia,
signer: LocalAccountSigner.privateKeyToAccountSigner(
process.env.PRIVATE_KEY! as Hex,
),
};

const clientWithoutAccount = createSmartWalletClient(clientParams);

const account = await clientWithoutAccount.requestAccount();

export const client = createSmartWalletClient({
...clientParams,
account: account.address,
signer,
});
```

Expand Down
42 changes: 5 additions & 37 deletions fern/wallets/pages/transactions/retry-transactions/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,10 @@ You will need to fill in values wrapped in curly braces like `{SIGNER_ADDRESS}`.

<Steps>

<Step title="(If needed) Request an account">

```bash
curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "wallet_requestAccount",
"params": [
{
"signerAddress": "{SIGNER_ADDRESS}"
}
]
}'
```

This returns:

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"accountAddress": "ACCOUNT_ADDRESS",
"id": "ACCOUNT_ID"
}
}
```

For other potential responses, [check out the API reference!](https://www.alchemy.com/docs/wallets/api-reference/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/wallet-request-account)

</Step>

<Step title="Send the initial transaction">

Use your signer address directly as the `from` field to enable [EIP-7702](/wallets/transactions/using-eip-7702) by default.

```bash
curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
-H "Content-Type: application/json" \
Expand All @@ -54,7 +22,7 @@ curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
"data": "{DATA}"
}
],
"from": "{ACCOUNT_ADDRESS}",
"from": "{SIGNER_ADDRESS}",
"chainId": "{CHAIN_ID}",
"capabilities": {
"paymasterService": {
Expand Down Expand Up @@ -87,7 +55,7 @@ This returns:
}
```

Sign the `raw` field and send the transaction as usual. See the [sending transactions documentation](/wallets/transactions/send-transactions) for more details.
Sign the `raw` field and send the transaction as usual. On the first transaction for a new account, the response type will be `array` containing both an EIP-7702 authorization and a user operation. See the [sending transactions documentation](/wallets/transactions/send-transactions) for more details.

</Step>

Expand Down Expand Up @@ -150,7 +118,7 @@ curl -X POST https://api.g.alchemy.com/v2/{API_KEY} \
"data": "{SAME_DATA}"
}
],
"from": "{ACCOUNT_ADDRESS}",
"from": "{SIGNER_ADDRESS}",
"chainId": "{CHAIN_ID}",
"capabilities": {
"paymasterService": {
Expand Down
Loading
Loading