From ff1d987281b26d9d6944bd71f5ee756a57ac94d6 Mon Sep 17 00:00:00 2001 From: linna Date: Fri, 10 Jan 2025 16:32:32 -0500 Subject: [PATCH 1/6] docs: updates usage of createSMAV2Account --- .../functions/createSMAV2Account.mdx | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx index d789f0559b..400f06997c 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx @@ -12,7 +12,42 @@ Handles account initialization code, nonce generation, transaction encoding, and ## Import ```ts -import { createSMAV2Account } from "@account-kit/smart-contracts"; +import { + createSMAV2AccountClient, + installValidationActions, +} from "@account-kit/smart-contracts/experimental"; +import { LocalAccountSigner } from "@aa-sdk/core"; +import { Address, Hex, http, parseEther } from "viem"; +import { + alchemy, + alchemyFeeEstimator, + alchemyGasManagerMiddleware, + createAlchemySmartAccountClient, + polygonAmoy, +} from "@account-kit/infra"; + +const OWNER_PRIVATE_KEY = "0x" as Hex; // TO DO: replace with your private key! + +const ownerSigner = + LocalAccountSigner.privateKeyToAccountSigner(OWNER_PRIVATE_KEY); + +const ALCHEMY_API_KEY = ""; // TO DO: replace with your Alchemy API key! + +const rpcTransport = http( + `https://polygon-amoy.g.alchemy.com/v2/${ALCHEMY_API_KEY}` +); + +const GAS_POLICY_ID = ""; // TO DO: replace with your gas policy ID! + +const accountClient = ( + await createSMAV2AccountClient({ + transport: alchemyTransport, + chain: polygonAmoy, + signer: ownerSigner, + feeEstimator: alchemyFeeEstimator(alchemyTransport), + ...alchemyGasManagerMiddleware(GAS_POLICY_ID), + }) + ).extend(installValidationActions); ``` ## Parameters From 4689f74f2665da0343a719bf5708bbdee80d1b86 Mon Sep 17 00:00:00 2001 From: linna Date: Fri, 10 Jan 2025 16:35:45 -0500 Subject: [PATCH 2/6] docs: moves example usage code snippet --- .../functions/createSMAV2Account.mdx | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx index 400f06997c..024e7793db 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx @@ -11,6 +11,23 @@ Handles account initialization code, nonce generation, transaction encoding, and ## Import +```ts +import { createSMAV2AccountClient } from "@account-kit/smart-contracts/experimental"; +``` + +## Parameters + +### config + +`CreateSMAV2AccountParams` +Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more. + +## Returns + +`Promise` +A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more. + +## Example ```ts import { createSMAV2AccountClient, @@ -49,15 +66,3 @@ const accountClient = ( }) ).extend(installValidationActions); ``` - -## Parameters - -### config - -`CreateSMAV2AccountParams` -Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more. - -## Returns - -`Promise` -A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more. From 5144ea8226d1765ffc03030e3fba8e96c5196394 Mon Sep 17 00:00:00 2001 From: linna Date: Fri, 10 Jan 2025 16:37:20 -0500 Subject: [PATCH 3/6] docs: moves changes to correct file --- .../functions/createSMAV2Account.mdx | 41 +------------- .../functions/createSMAV2AccountClient.mdx | 54 ++++++++++++------- 2 files changed, 36 insertions(+), 59 deletions(-) diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx index 024e7793db..9ef63b1c24 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx @@ -12,7 +12,7 @@ Handles account initialization code, nonce generation, transaction encoding, and ## Import ```ts -import { createSMAV2AccountClient } from "@account-kit/smart-contracts/experimental"; +import { createSMAV2Account } from "@account-kit/smart-contracts/experimental"; ``` ## Parameters @@ -27,42 +27,3 @@ Configuration parameters for creating an SMAV2 account. Includes chain details, `Promise` A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more. -## Example -```ts -import { - createSMAV2AccountClient, - installValidationActions, -} from "@account-kit/smart-contracts/experimental"; -import { LocalAccountSigner } from "@aa-sdk/core"; -import { Address, Hex, http, parseEther } from "viem"; -import { - alchemy, - alchemyFeeEstimator, - alchemyGasManagerMiddleware, - createAlchemySmartAccountClient, - polygonAmoy, -} from "@account-kit/infra"; - -const OWNER_PRIVATE_KEY = "0x" as Hex; // TO DO: replace with your private key! - -const ownerSigner = - LocalAccountSigner.privateKeyToAccountSigner(OWNER_PRIVATE_KEY); - -const ALCHEMY_API_KEY = ""; // TO DO: replace with your Alchemy API key! - -const rpcTransport = http( - `https://polygon-amoy.g.alchemy.com/v2/${ALCHEMY_API_KEY}` -); - -const GAS_POLICY_ID = ""; // TO DO: replace with your gas policy ID! - -const accountClient = ( - await createSMAV2AccountClient({ - transport: alchemyTransport, - chain: polygonAmoy, - signer: ownerSigner, - feeEstimator: alchemyFeeEstimator(alchemyTransport), - ...alchemyGasManagerMiddleware(GAS_POLICY_ID), - }) - ).extend(installValidationActions); -``` diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx index 8b7bcd96ab..94d0c74e2a 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx @@ -16,27 +16,43 @@ import { createSMAV2AccountClient } from "@account-kit/smart-contracts"; ``` ## Usage - ```ts -import { http } from "viem"; -import { createSMAV2AccountClient } from "@account-kit/smart-contracts"; +import { + createSMAV2AccountClient, + installValidationActions, +} from "@account-kit/smart-contracts/experimental"; import { LocalAccountSigner } from "@aa-sdk/core"; -import { sepolia } from "@account-kit/infra"; - -const MNEMONIC = "..."; -const RPC_URL = "..."; - -const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC); - -const chain = sepolia; - -const transport = http(RPC_URL); - -const SMAV2SignerAccountClient = await createSMAV2AccountClient({ - chain, - signer, - transport, -}); +import { Address, Hex, http, parseEther } from "viem"; +import { + alchemy, + alchemyFeeEstimator, + alchemyGasManagerMiddleware, + createAlchemySmartAccountClient, + polygonAmoy, +} from "@account-kit/infra"; + +const OWNER_PRIVATE_KEY = "0x" as Hex; // TO DO: replace with your private key! + +const ownerSigner = + LocalAccountSigner.privateKeyToAccountSigner(OWNER_PRIVATE_KEY); + +const ALCHEMY_API_KEY = ""; // TO DO: replace with your Alchemy API key! + +const rpcTransport = http( + `https://polygon-amoy.g.alchemy.com/v2/${ALCHEMY_API_KEY}` +); + +const GAS_POLICY_ID = ""; // TO DO: replace with your gas policy ID! + +const accountClient = ( + await createSMAV2AccountClient({ + transport: alchemyTransport, + chain: polygonAmoy, + signer: ownerSigner, + feeEstimator: alchemyFeeEstimator(alchemyTransport), + ...alchemyGasManagerMiddleware(GAS_POLICY_ID), + }) + ).extend(installValidationActions); ``` ## Parameters From aea403886ecb7a98c8693df8ea7450ed5236fee2 Mon Sep 17 00:00:00 2001 From: linna Date: Fri, 10 Jan 2025 16:38:44 -0500 Subject: [PATCH 4/6] docs: adds experimental to import --- .../smart-contracts/functions/createSMAV2AccountClient.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx index 94d0c74e2a..2bfc6d0b5a 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx @@ -12,7 +12,7 @@ Creates a SMAv2 account client using the provided configuration parameters. ## Import ```ts -import { createSMAV2AccountClient } from "@account-kit/smart-contracts"; +import { createSMAV2AccountClient } from "@account-kit/smart-contracts/experimental"; ``` ## Usage From caff389864e9bb5f71647ee25df52a023eca7bbc Mon Sep 17 00:00:00 2001 From: linna Date: Fri, 10 Jan 2025 17:05:50 -0500 Subject: [PATCH 5/6] refactor: fixes linting warnings --- .../example/src/screens/magic-link-auth.tsx | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/account-kit/rn-signer/example/src/screens/magic-link-auth.tsx b/account-kit/rn-signer/example/src/screens/magic-link-auth.tsx index fd59af8be2..6545c37f32 100644 --- a/account-kit/rn-signer/example/src/screens/magic-link-auth.tsx +++ b/account-kit/rn-signer/example/src/screens/magic-link-auth.tsx @@ -1,7 +1,7 @@ /* eslint-disable import/extensions */ import { RNAlchemySigner } from "@account-kit/react-native-signer"; import type { User } from "@account-kit/signer"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { Linking, StyleSheet, @@ -20,48 +20,54 @@ export default function MagicLinkAuthScreen() { const [email, setEmail] = useState(""); const [user, setUser] = useState(null); - const handleUserAuth = ({ bundle }: { bundle: string }) => { - signer - .authenticate({ - bundle, - type: "email", - }) - .then(setUser) - .catch(console.error); - }; + const handleUserAuth = useCallback( + ({ bundle }: { bundle: string }) => { + signer + .authenticate({ + bundle, + type: "email", + }) + .then(setUser) + .catch(console.error); + }, + [signer] + ); - const handleIncomingURL = (event: { url: string }) => { - const regex = /[?&]([^=#]+)=([^&#]*)/g; + const handleIncomingURL = useCallback( + (event: { url: string }) => { + const regex = /[?&]([^=#]+)=([^&#]*)/g; - let params: Record = {}; - let match: RegExpExecArray | null; + let params: Record = {}; + let match: RegExpExecArray | null; - while ((match = regex.exec(event.url))) { - if (match[1] && match[2]) { - params[match[1]] = match[2]; + while ((match = regex.exec(event.url))) { + if (match[1] && match[2]) { + params[match[1]] = match[2]; + } } - } - if (!params.bundle || !params.orgId) { - return; - } + if (!params.bundle || !params.orgId) { + return; + } - handleUserAuth({ - bundle: params.bundle ?? "", - }); - }; + handleUserAuth({ + bundle: params.bundle ?? "", + }); + }, + [handleUserAuth] + ); useEffect(() => { // get the user if already logged in signer.getAuthDetails().then(setUser); - }, []); + }, [signer]); // Add listener for incoming links useEffect(() => { const subscription = Linking.addEventListener("url", handleIncomingURL); return () => subscription.remove(); - }, []); + }, [handleIncomingURL]); return ( From 559de84b4b882058f09c0c8edbdbe6e6213da4f5 Mon Sep 17 00:00:00 2001 From: linna Date: Fri, 10 Jan 2025 17:07:39 -0500 Subject: [PATCH 6/6] fix: fixes lint warnings --- account-kit/rn-signer/example/metro.config.js | 2 -- .../functions/createSMAV2Account.mdx | 1 - .../functions/createSMAV2AccountClient.mdx | 17 +++++++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/account-kit/rn-signer/example/metro.config.js b/account-kit/rn-signer/example/metro.config.js index ead41fe3b5..0d04b2b063 100644 --- a/account-kit/rn-signer/example/metro.config.js +++ b/account-kit/rn-signer/example/metro.config.js @@ -1,7 +1,5 @@ const path = require("path"); const { getDefaultConfig } = require("@react-native/metro-config"); -const { getConfig } = require("react-native-builder-bob/metro-config"); -const pkg = require("../package.json"); const rnSignerRoot = path.resolve(__dirname, ".."); const projectRoot = __dirname; diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx index 9ef63b1c24..7c2eaa88e0 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx @@ -26,4 +26,3 @@ Configuration parameters for creating an SMAV2 account. Includes chain details, `Promise` A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more. - diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx index 2bfc6d0b5a..33da35fa28 100644 --- a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx @@ -16,6 +16,7 @@ import { createSMAV2AccountClient } from "@account-kit/smart-contracts/experimen ``` ## Usage + ```ts import { createSMAV2AccountClient, @@ -45,14 +46,14 @@ const rpcTransport = http( const GAS_POLICY_ID = ""; // TO DO: replace with your gas policy ID! const accountClient = ( - await createSMAV2AccountClient({ - transport: alchemyTransport, - chain: polygonAmoy, - signer: ownerSigner, - feeEstimator: alchemyFeeEstimator(alchemyTransport), - ...alchemyGasManagerMiddleware(GAS_POLICY_ID), - }) - ).extend(installValidationActions); + await createSMAV2AccountClient({ + transport: alchemyTransport, + chain: polygonAmoy, + signer: ownerSigner, + feeEstimator: alchemyFeeEstimator(alchemyTransport), + ...alchemyGasManagerMiddleware(GAS_POLICY_ID), + }) +).extend(installValidationActions); ``` ## Parameters