@atxp/base 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/baseAppAccount.d.ts.map +1 -1
- package/dist/baseAppAccount.js +9 -1
- package/dist/baseAppAccount.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# ATXP Base
|
|
2
|
+
|
|
3
|
+
ATXP is a framework for building and running agents that can interact with the world. See [docs.atxp.ai](https://docs.atxp.ai) for documentation and examples.
|
|
4
|
+
|
|
5
|
+
ATXP Base provides a `BaseAppAccount` implementation for using `@atxp/client` with [Base Mini Apps](https://www.base.org/build/mini-apps).
|
|
6
|
+
|
|
7
|
+
## Initializing the account
|
|
8
|
+
In your Base Mini App's React code:
|
|
9
|
+
```
|
|
10
|
+
import { BaseAppAccount } from "@atxp/base";
|
|
11
|
+
|
|
12
|
+
// This example uses wagmi to fetch the user wallet address, but any
|
|
13
|
+
// equivalent method that returns the address should work
|
|
14
|
+
import { useAccount } from "wagmi";
|
|
15
|
+
const { address } = useAccount();
|
|
16
|
+
|
|
17
|
+
// Base mini app API key from the Coinbase Developer Portal
|
|
18
|
+
const apiKey = process.env.NEXT_PUBLIC_ONCHAINKIT_API_KEY!;
|
|
19
|
+
|
|
20
|
+
const account = await BaseAppAccount.initialize({
|
|
21
|
+
walletAddress: address,
|
|
22
|
+
apiKey,
|
|
23
|
+
appName: 'Mini App ATXP',
|
|
24
|
+
// Parameters for the spend permission (see How it works below)
|
|
25
|
+
allowance: BigInt('10000000'), // 10 USDC
|
|
26
|
+
periodInDays: 30,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Then, use the account as you would any other Account - see
|
|
30
|
+
// docs.atxp.ai for full docs and examples
|
|
31
|
+
const client = atxpClient({
|
|
32
|
+
account,
|
|
33
|
+
mcpServer: 'https://browse.mcp.atxp.ai/'
|
|
34
|
+
});
|
|
35
|
+
const res = await client.callTool({
|
|
36
|
+
name: 'atxp_browse',
|
|
37
|
+
{query: 'How do I make a mini app?'}
|
|
38
|
+
);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Clearing state
|
|
43
|
+
You can reset the BaseAppAccount state for a user by:
|
|
44
|
+
```
|
|
45
|
+
BaseAppAccount.clearAllStoredData(address);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This will wipe any existing spend permission and ephemeral wallet for the given address. It will be automatically re-created the next time you call `BaseAppAccount.iniitalize` for that address.
|
|
49
|
+
|
|
50
|
+
**Note that this will change the accountId of the user in called MCP servers, so this is recommended mainly for development flows**
|
|
51
|
+
|
|
52
|
+
The ephemeral account does not store any tokens, so you shouldn't loose access to funds by doing this. There is a small ETH gas cost to creating the spend permission and ephemeral wallet, though.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## How it works
|
|
56
|
+
When you call `BaseAppAccount.initialize` for the first time, it will:
|
|
57
|
+
1. Create a new ephemeral smart wallet for the user for this mini-app.
|
|
58
|
+
2. Create a new [Spend Permission](https://docs.base.org/base-account/improve-ux/spend-permissions) for the ephemeral wallet, and ask the user to approve it. (Using this approach means that the user only has to approve once up-front, instead of approving every single ATXP transaction as they occur)
|
|
59
|
+
3. Deploy the ephemeral wallet
|
|
60
|
+
4. Store the permission and wallet in LocalStorage for subsequent use
|
|
61
|
+
|
|
62
|
+
Subsequent calls to `BaseAppAccount.initialize` will load the stored Spend Permission and ephemeral wallet from LocalStorage so they don't need to be recreated.
|
|
63
|
+
|
|
64
|
+
When authenticating to an MCP server, `BaseAppAccount` will use the address of the ephemeral wallet.
|
|
65
|
+
|
|
66
|
+
When an MCP request requires payment, `BaseAppAccount` will:
|
|
67
|
+
1. Use the ephemeral wallet to make a payment from the user's wallet to the destiniation using the Spend Permission
|
|
68
|
+
2. It will use ATXP's paymaster, so all gas fees are paid by ATXP.
|
|
69
|
+
|
|
70
|
+
The ephemeral wallet never holds any ETH or USDC.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseAppAccount.d.ts","sourceRoot":"","sources":["../src/baseAppAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM1D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAA0D,MAAM,cAAc,CAAC;AAChG,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAiB,MAAM,EAAE,MAAM,cAAc,CAAC;AAQrD,qBAAa,cAAe,YAAW,OAAO;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAC;IAE/C,OAAO,CAAC,MAAM,CAAC,YAAY;WAId,UAAU,CAAC,MAAM,EAAE;QAC5B,aAAa,EAAE,MAAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,GACA,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"baseAppAccount.d.ts","sourceRoot":"","sources":["../src/baseAppAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM1D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAA0D,MAAM,cAAc,CAAC;AAChG,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAiB,MAAM,EAAE,MAAM,cAAc,CAAC;AAQrD,qBAAa,cAAe,YAAW,OAAO;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAC;IAE/C,OAAO,CAAC,MAAM,CAAC,YAAY;WAId,UAAU,CAAC,MAAM,EAAE;QAC5B,aAAa,EAAE,MAAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,GACA,OAAO,CAAC,cAAc,CAAC;IA6D1B,OAAO,CAAC,MAAM,CAAC,4BAA4B;mBAkBtB,iBAAiB;gBAsBpC,eAAe,EAAE,eAAe,EAChC,oBAAoB,EAAE,oBAAoB,EAC1C,MAAM,CAAC,EAAE,MAAM;IAajB,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;CAQvF"}
|
package/dist/baseAppAccount.js
CHANGED
|
@@ -39,7 +39,15 @@ export class BaseAppAccount {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
const provider = sdk.getProvider();
|
|
42
|
-
|
|
42
|
+
// Some wallets don't support wallet_connect, so
|
|
43
|
+
// will just continue if it fails
|
|
44
|
+
try {
|
|
45
|
+
await provider.request({ method: 'wallet_connect' });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// Continue if wallet_connect is not supported
|
|
49
|
+
logger.warn(`wallet_connect not supported, continuing with initialization. ${error}`);
|
|
50
|
+
}
|
|
43
51
|
const privateKey = generatePrivateKey();
|
|
44
52
|
const smartWallet = await toEphemeralSmartWallet(privateKey, config.apiKey);
|
|
45
53
|
logger.info(`Generated ephemeral wallet: ${smartWallet.address}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseAppAccount.js","sourceRoot":"","sources":["../src/baseAppAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnC,OAAO,EAAY,cAAc,EAAE,mBAAmB,EAAqB,MAAM,cAAc,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAA6B,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAU,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,aAAa,GAAG,iFAAiF,CAAC;AAExG,MAAM,OAAO,cAAc;IAIjB,MAAM,CAAC,YAAY,CAAC,iBAAyB;QACnD,OAAO,wBAAwB,iBAAiB,EAAE,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,MAQrB;QAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACpD,sCAAsC;QACtC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,oCAAoC;gBACpC,wDAAwD,CACzD,CAAC;QACJ,CAAC;QAED,qBAAqB;QACrB,MAAM,WAAW,GAAG,MAAM,EAAE,OAAO,IAAI,IAAI,cAAc,EAAE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AAgC,EAChC,oBAA0C,EAC1C,MAAe;QAEf,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,oBAAoB,CAAC,OAAO,CAAC;QAE9C,IAAI,CAAC,aAAa,GAAG;YACnB,MAAM,EAAE,IAAI,mBAAmB,CAAC,eAAe,EAAE,oBAAoB,EAAE,MAAM,CAAC;SAC/E,CAAA;IACH,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,iBAAyB,EAAE,OAA0B;QAC7E,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,OAAO,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC;QAC1G,CAAC;QACD,OAAO,GAAG,OAAO,IAAI,IAAI,cAAc,EAAE,CAAC;QAE1C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACvD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atxp/base",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "ATXP for Base Mini Apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"test": "vitest run"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atxp/client": "0.2.
|
|
26
|
-
"@atxp/common": "0.2.
|
|
25
|
+
"@atxp/client": "0.2.16",
|
|
26
|
+
"@atxp/common": "0.2.16",
|
|
27
27
|
"@base-org/account": "^2.0.2",
|
|
28
28
|
"bignumber.js": "^9.3.0",
|
|
29
29
|
"viem": "^2.34.0"
|