Skip to content

Commit 41ff94c

Browse files
author
“AyushBherwani1998”
committed
add new API reference for smart account
1 parent bbdcaf2 commit 41ff94c

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

delegation-toolkit/reference/api/smart-account.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,61 @@ export const bundlerClient = createBundlerClient({
116116
</TabItem>
117117
</Tabs>
118118

119+
## `encodeCalls`
120+
121+
Encodes calls for execution by MetaMask smart account contract. If there's a single call directly to the smart account, it returns the call data directly. For multiple calls or calls to other addresses, it creates executions and encodes them for the smart account's `execute` function.
122+
123+
The execution mode is set to `SINGLE_DEFAULT_MODE` for a single call to other address, or `BATCH_DEFAULT_MODE` for multiple calls. [Learn more about execution modes](../../how-to/redeem-delegation#execution-modes).
124+
125+
### Example
126+
127+
<Tabs>
128+
<TabItem value ="example.ts">
129+
130+
```ts
131+
import { smartAccount } from "./config.ts";
132+
133+
const calls = [{
134+
to: zeroAddress,
135+
data: "0x",
136+
value: 0n
137+
}];
138+
139+
const executeCallData = await smartAccount.encodeCalls(calls);
140+
```
141+
142+
</TabItem>
143+
144+
<TabItem value ="config.ts">
145+
146+
```ts
147+
import { createPublicClient, http } from "viem";
148+
import { privateKeyToAccount } from "viem/accounts";
149+
import { sepolia as chain } from "viem/chains";
150+
import {
151+
Implementation,
152+
toMetaMaskSmartAccount,
153+
} from "@metamask/delegation-toolkit";
154+
155+
const publicClient = createPublicClient({
156+
chain,
157+
transport: http(),
158+
});
159+
160+
const delegatorAccount = privateKeyToAccount("0x...");
161+
162+
export const smartAccount = await toMetaMaskSmartAccount({
163+
client: publicClient,
164+
implementation: Implementation.Hybrid,
165+
deployParams: [delegatorAccount.address, [], [], []],
166+
deploySalt: "0x",
167+
signatory: { account: delegatorAccount },
168+
});
169+
```
170+
171+
</TabItem>
172+
</Tabs>
173+
119174
## `getFactoryArgs`
120175

121176
Returns the factory address and factory data that can be used to deploy the smart account.
@@ -163,6 +218,54 @@ export const smartAccount = await toMetaMaskSmartAccount({
163218
</TabItem>
164219
</Tabs>
165220

221+
222+
## `getNonce`
223+
224+
Returns the nonce for smart account.
225+
226+
### Example
227+
228+
<Tabs>
229+
<TabItem value ="example.ts">
230+
231+
```ts
232+
import { smartAccount } from "./config.ts";
233+
234+
const nonce = await smartAccount.getNonce();
235+
```
236+
237+
</TabItem>
238+
239+
<TabItem value ="config.ts">
240+
241+
```ts
242+
import { createPublicClient, http } from "viem";
243+
import { privateKeyToAccount } from "viem/accounts";
244+
import { sepolia as chain } from "viem/chains";
245+
import {
246+
Implementation,
247+
toMetaMaskSmartAccount,
248+
} from "@metamask/delegation-toolkit";
249+
250+
const publicClient = createPublicClient({
251+
chain,
252+
transport: http(),
253+
});
254+
255+
const delegatorAccount = privateKeyToAccount("0x...");
256+
257+
export const smartAccount = await toMetaMaskSmartAccount({
258+
client: publicClient,
259+
implementation: Implementation.Hybrid,
260+
deployParams: [delegatorAccount.address, [], [], []],
261+
deploySalt: "0x",
262+
signatory: { account: delegatorAccount },
263+
});
264+
```
265+
266+
</TabItem>
267+
</Tabs>
268+
166269
## `signDelegation`
167270

168271
Signs the delegation and returns the delegation signature.

0 commit comments

Comments
 (0)