@rhinestone/sdk 0.7.1 → 0.7.3
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 +29 -50
- package/dist/src/accounts/index.d.ts +3 -15511
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/nexus.d.ts +5 -23266
- package/dist/src/accounts/nexus.d.ts.map +1 -1
- package/dist/src/accounts/safe.d.ts +4 -15511
- package/dist/src/accounts/safe.d.ts.map +1 -1
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +15 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,9 +28,10 @@ You'll need a Rhinestone API key, as well as an existing account with some testn
|
|
|
28
28
|
|
|
29
29
|
### Creating a Wallet
|
|
30
30
|
|
|
31
|
-
Let's create a single
|
|
31
|
+
Let's create a smart account with a single owner:
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
+
import { createRhinestoneAccount } from '@rhinestone/sdk'
|
|
34
35
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
|
|
35
36
|
import { baseSepolia, arbitrumSepolia, optimismSepolia } from 'viem/chains'
|
|
36
37
|
import {
|
|
@@ -44,8 +45,6 @@ import {
|
|
|
44
45
|
parseEther,
|
|
45
46
|
} from 'viem'
|
|
46
47
|
|
|
47
|
-
import { createRhinestoneAccount } from '@rhinestone/sdk'
|
|
48
|
-
|
|
49
48
|
const fundingPrivateKey = process.env.FUNDING_PRIVATE_KEY
|
|
50
49
|
if (!fundingPrivateKey) {
|
|
51
50
|
throw new Error('FUNDING_PRIVATE_KEY is not set')
|
|
@@ -59,67 +58,43 @@ if (!rhinestoneApiKey) {
|
|
|
59
58
|
const sourceChain = baseSepolia
|
|
60
59
|
const targetChain = arbitrumSepolia
|
|
61
60
|
|
|
62
|
-
const fundingAccount = privateKeyToAccount(fundingPrivateKey as Hex)
|
|
63
|
-
const publicClient = createPublicClient({
|
|
64
|
-
chain: sourceChain,
|
|
65
|
-
transport: http(),
|
|
66
|
-
})
|
|
67
|
-
const fundingClient = createWalletClient({
|
|
68
|
-
account: fundingAccount,
|
|
69
|
-
chain: sourceChain,
|
|
70
|
-
transport: http(),
|
|
71
|
-
})
|
|
72
|
-
|
|
73
61
|
// You can use an existing PK here
|
|
74
62
|
const privateKey = generatePrivateKey()
|
|
75
|
-
console.log(
|
|
63
|
+
console.log(`Owner private key: ${privateKey}`)
|
|
76
64
|
const account = privateKeyToAccount(privateKey)
|
|
77
65
|
|
|
78
66
|
const rhinestoneAccount = await createRhinestoneAccount({
|
|
79
|
-
account: {
|
|
80
|
-
type: 'nexus',
|
|
81
|
-
},
|
|
82
67
|
owners: {
|
|
83
68
|
type: 'ecdsa',
|
|
84
69
|
accounts: [account],
|
|
85
70
|
}
|
|
86
71
|
rhinestoneApiKey,
|
|
87
|
-
// Optional, used to deploy the account on the source chain
|
|
88
|
-
deployerAccount: fundingAccount,
|
|
89
|
-
// Alternatively, you can use an ERC-4337 bundler to deploy
|
|
90
|
-
// bundler: { … }
|
|
91
72
|
})
|
|
92
|
-
const address = await rhinestoneAccount.getAddress(
|
|
93
|
-
console.log(address)
|
|
73
|
+
const address = await rhinestoneAccount.getAddress()
|
|
74
|
+
console.log(`Smart account address: ${address}`)
|
|
94
75
|
```
|
|
95
76
|
|
|
96
77
|
### Funding the Account
|
|
97
78
|
|
|
98
|
-
We will send some ETH from the funding account to the created
|
|
79
|
+
We will send some ETH from the funding account to the created smart account. The Orchestrator will use some of that ETH to deploy the account on the target chain, as well as to convert it to USDC for a transfer transaction.
|
|
99
80
|
|
|
100
81
|
```ts
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
82
|
+
const publicClient = createPublicClient({
|
|
83
|
+
chain: sourceChain,
|
|
84
|
+
transport: http(),
|
|
85
|
+
});
|
|
86
|
+
const fundingAccount = privateKeyToAccount(fundingPrivateKey as Hex);
|
|
87
|
+
const fundingClient = createWalletClient({
|
|
88
|
+
account: fundingAccount,
|
|
89
|
+
chain: sourceChain,
|
|
90
|
+
transport: http(),
|
|
91
|
+
});
|
|
104
92
|
|
|
105
93
|
const txHash = await fundingClient.sendTransaction({
|
|
106
94
|
to: address,
|
|
107
95
|
value: parseEther('0.001'),
|
|
108
|
-
})
|
|
109
|
-
await publicClient.waitForTransactionReceipt({ hash: txHash })
|
|
110
|
-
|
|
111
|
-
function getTokenAddress(chain: Chain) {
|
|
112
|
-
switch (chain.id) {
|
|
113
|
-
case baseSepolia.id:
|
|
114
|
-
return '0x036cbd53842c5426634e7929541ec2318f3dcf7e'
|
|
115
|
-
case arbitrumSepolia.id:
|
|
116
|
-
return '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d'
|
|
117
|
-
case optimismSepolia.id:
|
|
118
|
-
return '0x5fd84259d66Cd46123540766Be93DFE6D43130D7'
|
|
119
|
-
default:
|
|
120
|
-
throw new Error('Unsupported chain')
|
|
121
|
-
}
|
|
122
|
-
}
|
|
96
|
+
});
|
|
97
|
+
await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
123
98
|
```
|
|
124
99
|
|
|
125
100
|
### Sending a Cross-chain Transaction
|
|
@@ -127,7 +102,10 @@ function getTokenAddress(chain: Chain) {
|
|
|
127
102
|
Finally, let's make a cross-chain token transfer:
|
|
128
103
|
|
|
129
104
|
```ts
|
|
130
|
-
const
|
|
105
|
+
const usdcTarget = '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d';
|
|
106
|
+
const usdcAmount = 1n;
|
|
107
|
+
|
|
108
|
+
const transaction = await rhinestoneAccount.sendTransaction({
|
|
131
109
|
sourceChain,
|
|
132
110
|
targetChain,
|
|
133
111
|
calls: [
|
|
@@ -147,13 +125,15 @@ const bundleId = await rhinestoneAccount.sendTransaction({
|
|
|
147
125
|
amount: usdcAmount,
|
|
148
126
|
},
|
|
149
127
|
],
|
|
150
|
-
})
|
|
151
|
-
console.log('
|
|
128
|
+
});
|
|
129
|
+
console.log('Transaction', transaction);
|
|
152
130
|
|
|
153
|
-
const
|
|
154
|
-
console.log('
|
|
131
|
+
const transactionResult = await rhinestoneAccount.waitForExecution(transaction);
|
|
132
|
+
console.log('Result', transactionResult);
|
|
155
133
|
```
|
|
156
134
|
|
|
135
|
+
After running that, you will get a smart account deployed on both Base Sepolia and Arbitrum Sepolia, and make a cross-chain USDC transfer.
|
|
136
|
+
|
|
157
137
|
### Using Smart Sessions
|
|
158
138
|
|
|
159
139
|
First, define a session you want to use:
|
|
@@ -207,7 +187,7 @@ const rhinestoneAccount = await createRhinestoneAccount({
|
|
|
207
187
|
sessions: [session],
|
|
208
188
|
bundler: {
|
|
209
189
|
// …
|
|
210
|
-
}
|
|
190
|
+
},
|
|
211
191
|
})
|
|
212
192
|
```
|
|
213
193
|
|
|
@@ -223,7 +203,6 @@ const transactionResult = await rhinestoneAccount.sendTransaction({
|
|
|
223
203
|
})
|
|
224
204
|
```
|
|
225
205
|
|
|
226
|
-
|
|
227
206
|
## Contributing
|
|
228
207
|
|
|
229
208
|
For feature or change requests, feel free to open a PR, start a discussion or get in touch with us.
|