You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Use the x402 protocol for per-request HTTP payments on Stellar, with support for AI agents and APIs."
6
+
---
7
+
8
+
## What is x402?
9
+
10
+
x402 is an open protocol from the Coinbase Developer Platform that enables programmatic, per request payments over HTTP, designed especially for AI agents and APIs. It effectively turns the old “402 Payment Required” HTTP status code into something usable, for both humans and AI agents.
11
+
12
+
On Stellar, x402 works with Soroban authorization so that clients can pay for API requests via signed auth entries, ideal for micropayments and payment enabled apps. To build an x402-enabled service or integrate payments into your app, see [Build Applications](./README.mdx) and the resources below.
13
+
14
+
## x402 Compatible Wallets
15
+
16
+
To support x402 on Stellar, a wallet must support [auth-entry signing](../guides/transactions/signing-soroban-invocations.mdx#method-2-auth-entry-signing) (Soroban authorization entry signing). The following wallets support auth-entry signing:
17
+
18
+
- Freighter Browser Extension
19
+
- Albedo
20
+
- Hana
21
+
- HOT
22
+
- Klever
23
+
- One Key
24
+
25
+
:::note
26
+
27
+
Freighter Mobile does not currently support x402; use the Freighter browser extension. Mobile support is planned for a future release.
28
+
29
+
:::
30
+
31
+
## x402 Facilitator from OpenZeppelin
32
+
33
+
The [OpenZeppelin Relayer x402 Plugin for x402](https://github.com/OpenZeppelin/relayer-plugin-x402-facilitator) implements the x402 facilitator API so you can serve x402 payments directly from a Relayer instance. It works with the Coinbase x402 ecosystem (e.g., @x402/express) and exposes the expected `/verify`, `/settle`, and `/supported` endpoints under the Relayer plugin router.
34
+
35
+
:::note
36
+
37
+
This version supports x402 v2 specification. For x402 v1 support, please use a previous version of this plugin (check git history for v1 compatible releases).
38
+
39
+
:::
40
+
41
+
## Resources
42
+
43
+
-**x402 Starter Template** — A starter template for building payment-enabled applications with x402. Simplified scaffolding demonstrating x402 payment protocol integration with browser wallet support; use it as a foundation for micropayment-enabled services, SaaS applications, or any project that needs frictionless web payments. [View on GitHub](https://github.com/ElliotFriend/x402/tree/stellar-browser-wallet-example/examples/typescript/fullstack/browser-wallet-example)
44
+
-**Economic Load Balancer** — An intelligent multi-chain payment router that automatically selects the most cost-efficient network for high-frequency AI agent micropayments. [View on GitHub](https://github.com/marcelosalloum/x402/tree/x402-hackathon)
45
+
46
+
## Learn more
47
+
48
+
-[x402 protocol (Coinbase Developer Platform)](https://docs.cdp.coinbase.com/x402) — Official x402 protocol overview and spec
49
+
-[Signing Soroban invocations](../guides/transactions/signing-soroban-invocations.mdx) — Auth-entry signing and transaction signing on Stellar
Copy file name to clipboardExpand all lines: docs/build/guides/conventions/cross-contract.mdx
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Making cross-contract calls
3
3
description: Call a smart contract from within another smart contract
4
4
---
5
5
6
-
As with developing software in any language, developing a Stellar smart contract with a rich feature set can be a challenging and time-consuming task. Thankfully, someone else might already have solved part of your issues or build components which could be reused. The open source community is vibrant and Stellar's community does not disappoint.
6
+
As with developing software in any language, developing a Stellar smart contract with a rich feature set can be a challenging and time-consuming task. Thankfully, someone else might already have solved part of your issues or built components which can be reused. The open source community is vibrant and Stellar's community does not disappoint.
7
7
8
8
There are two kinds of dependencies that can be introduced in a Stellar smart contract:
9
9
@@ -14,7 +14,7 @@ In the following, we will see how contracts can be leveraged from within another
14
14
15
15
## Contract as a dependency
16
16
17
-
While finding a contract is out of scope for this guide, there are a few place to be on the lookout. Most projects and dApps publicly disclose the address of their Stellar smart contract on their website. With this information, a [block explorer](../../../tools/developer-tools/block-explorers.mdx) is a powerful tool to understand how a contract is being used. Some explorers also allow you to download the compiled contract as a Wasm file. There are also projects that provide a link to access the code itself.
17
+
While finding a contract is out of scope for this guide, there are a few places to be on the lookout. Most projects and dApps publicly disclose the address of their Stellar smart contract on their website. With this information, a [block explorer](../../../tools/developer-tools/block-explorers.mdx) is a powerful tool to understand how a contract is being used. Some explorers also allow you to download the compiled contract as a Wasm file. There are also projects that provide a link to access the code itself.
18
18
19
19
:::info[Contract address]
20
20
@@ -24,17 +24,17 @@ To depend on a project, we need to know the contract address of the contract to
24
24
25
25
## Public API
26
26
27
-
All public functions of a contract can be called. Using a network explorer can be helpful as some propose to see the Rust interface of a contract. Bindings can also be generated using the CLI:
27
+
All public functions of a contract can be called. Using a network explorer can be helpful as some allow you to see the Rust interface of a contract. Bindings can also be generated using the CLI:
Once we know which function to call and which arguments to use, there are two main ways to make a cross-contract call: we can either load the Wasm or call the contract.
35
+
Once we know which function to call and which arguments to use, there are two main ways to make a cross-contract call: we can either manually invoke the contract or use a contract client.
36
36
37
-
Let's start by using only a contract's address. In this example, we have an external contract with a public function named `add_with` which takes two `u32` as input values to sum them.
37
+
Let's start by manually invoking the contract using only a contract's address. In this example, we have an external contract with a public function named `add_with` which takes two `u32` as input values to sum them.
38
38
39
39
```rust
40
40
#[contract]
@@ -48,7 +48,9 @@ impl ContractB {
48
48
}
49
49
```
50
50
51
-
Only using the contract comes with its own challenges. Because we don't have access to the Wasm code, we don't have any typing inference and have to manually convert function inputs to `Val`. If we want more tools to help us, we can load the Wasm code in the contract. This allows us to pass normal types without needing manual conversions from our side. Behind the scenes, this way of doing it is simply a convenient wrapper around `env.invoke_contract`.
51
+
Only using the contract address comes with its own challenges. We don't have a contract client so we don't have any typing inference, and have to manually convert function inputs to `Val`.
52
+
53
+
If we want more tools to help us, we need to get access to a contract client. A common way to do this is to load the Wasm of a contract using `contractimport!`. This allows us to pass normal types without needing manual conversions from our side. Behind the scenes, this way of doing it is simply a convenient wrapper around `env.invoke_contract`.
In the examples above, we have used `env.invoke_contract` and `client.some_function`. In both cases, if there is an issue with the underlying contract call, the contract will panic. This might be a valid approach, but in some cases we want to catch errors and handle them depending on the outcome. This is to forward a custom error message, or even triggers an alternative code path.
88
+
In the examples above, we have used `env.invoke_contract` and `client.some_function`. In both cases, if there is an issue with the underlying contract call, the contract will panic. This might be a valid approach, but in some cases we want to catch errors and handle them depending on the outcome. This allows you to forward a custom error message, or even trigger an alternative code path.
87
89
88
90
Enter `try_`. By using `env.try_invoke_contract` or `client.try_some_function`, underlying errors won't make the contract panic. Instead, errors will be wrapped and can be handled. For example if we wanted to default to 0 in case of an error:
@@ -46,7 +46,7 @@ cd soroban-examples/deployer/deployer
46
46
47
47
:::note
48
48
49
-
For this example to work, you should navigate to `deployer/contracts` and `deployer/deployer` and run the command `stellar contract build` in each directory to generate the target files.
49
+
For this example to work, you should navigate to `deployer/contract` and `deployer/deployer` and run the command `stellar contract build` in each directory to generate the target files.
50
50
51
51
:::
52
52
@@ -219,8 +219,6 @@ stellar contract invoke \
219
219
--init_args '[{"u32":8}]'
220
220
```
221
221
222
-
replace `alice` with your own identity
223
-
224
222
The deployer contract invocation will return the Contract address (For example: `CCTVFX6BFTQHTGAHA5TY4YZQJRUKRE2RRNUTGVBNKE3PJF5C7CI53APY`) of the newly deployed test contract.
225
223
226
224
Invoke the deployed test contract using the address returned from the previous command.
Copy file name to clipboardExpand all lines: docs/build/guides/conventions/deploy-sac-with-code.mdx
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ description: Deploy a SAC for a Stellar asset using Javascript SDK
20
20
21
21
## Overview
22
22
23
-
In this guide, you'll learn how to deploy a [Stellar Asset Contract (SAC)](../../../tokens/stellar-asset-contract.mdx) for a Stellar asset using the [Stellar SDK](../../../tools/sdks/client-sdks.mdx#javascript-sdk). The Stellar SDK is a set of tools and library designed to help developers build applications that interact with the Stellar blockchain network.
23
+
In this guide, you'll learn how to deploy a [Stellar Asset Contract (SAC)](../../../tokens/stellar-asset-contract.mdx) for a Stellar asset using the [Stellar SDK](../../../tools/sdks/client-sdks.mdx#javascript-sdk). The Stellar SDK is a set of tools and libraries designed to help developers build applications that interact with the Stellar blockchain network.
24
24
25
25
### Prerequisites:
26
26
@@ -33,10 +33,9 @@ In this guide, you'll learn how to deploy a [Stellar Asset Contract (SAC)](../..
console.error("An error occurred while Deploying assets:", e);
140
138
}
141
139
};
142
-
143
-
awaitdeployStellarAssetContract();
144
140
```
145
141
146
142
This function is designed to deploy a Stellar Asset Contract (SAC) on the Soroban testnet.
@@ -150,4 +146,4 @@ This function is designed to deploy a Stellar Asset Contract (SAC) on the Soroba
150
146
-**Custom Asset**: Defines a custom asset with the code `JOEBOY` and the issuer's public key.
151
147
-**Transaction Building**: A transaction is built using the `TransactionBuilder`, which includes the `createStellarAssetContract` operation for the custom asset. The transaction is then prepared and signed.
152
148
-**Send Transaction**: The signed transaction is sent to the network using `server.sendTransaction`.
153
-
-**Feedback Handling**: It waits for the transaction feedback using the `submitTx` function to ensure it has succeeded. extracts the contract buffer from the feedback and converts it to a contract ID using `StellarSdk.Address`. finally, it logs the contract ID for the deployed asset.
149
+
-**Feedback Handling**: It waits for the transaction feedback using the `submitTx` function to ensure it has succeeded. Then, it extracts the return value and converts it to a contract ID using `StellarSdk.Address`. Finally, it logs the contract ID for the deployed asset.
Copy file name to clipboardExpand all lines: docs/build/guides/conventions/error-enum.mdx
+28-10Lines changed: 28 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
2
title: Organize contract errors with an error enum type
3
3
hide_table_of_contents: true
4
-
description: Manage and communicate contract errors using an enum struct stored as Status values
4
+
description: Manage and communicate contract errors using an enum struct
5
5
---
6
6
7
-
A convenient way to manage and meaningfully communicate contract errors is to collect them into an `enum` struct. These errors are a special type of enum integer type that are stored on ledger as Status values containing a `u32` code. First, create the `Error` struct in your smart contract.
7
+
A convenient way to manage and meaningfully communicate contract errors is to collect them into an `enum` struct. These errors are a special type of enum integer type that are stored on the ledger as Error values containing a `u32` code. First, create the `Error` struct in your smart contract.
8
8
9
9
```rust
10
10
#[contracterror]
@@ -18,18 +18,36 @@ pub enum Error {
18
18
}
19
19
```
20
20
21
-
Then, panic with an error when the conditions are met. This example will panic with the specified error.
21
+
Smart contracts can fail with error enums in two different ways. They can either return a `Result` with their intended return value and the `#[contracterror]` struct as the error, or just invoke `panic_with_error!` with the appropriate Error enum value whenever an error condition is reached. By default, most ecosystem standards assume that contract functions do not return a `Result`, so using `panic_with_error!` is recommended.
22
+
23
+
However, both styles behave in the same way. If an error is returned or `panic_with_error!` is invoked, the transaction will fail. Contracts making cross contract calls have the ability to catch and handle these failures with `try_` functions.
0 commit comments