Skip to content

Commit 78a163c

Browse files
claim flow
1 parent d59413e commit 78a163c

File tree

2 files changed

+83
-81
lines changed

2 files changed

+83
-81
lines changed

packages/thirdweb/src/transaction/actions/send-transaction.test.ts

Lines changed: 83 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import * as ox__Hex from "ox/Hex";
21
import { describe, expect, it, vi } from "vitest";
32
import { TEST_WALLET_B } from "../../../test/src/addresses.js";
43
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
54
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
6-
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
5+
import {
6+
TEST_ACCOUNT_A,
7+
TEST_ACCOUNT_B,
8+
} from "../../../test/src/test-wallets.js";
79
import { defineChain } from "../../chains/utils.js";
810
import { getContract } from "../../contract/contract.js";
9-
import { getRpcClient } from "../../rpc/rpc.js";
10-
import { privateKeyToAccount } from "../../wallets/private-key.js";
11+
import { claimTo } from "../../extensions/erc20/drops/write/claimTo.js";
1112
import { getWalletBalance } from "../../wallets/utils/getWalletBalance.js";
1213
import { prepareContractCall } from "../prepare-contract-call.js";
1314
import { prepareTransaction } from "../prepare-transaction.js";
1415
import * as TransactionStore from "../transaction-store.js";
16+
import { encode } from "./encode.js";
1517
import { sendAndConfirmTransaction } from "./send-and-confirm-transaction.js";
1618
import { sendTransaction } from "./send-transaction.js";
1719

@@ -38,97 +40,99 @@ describe("sendTransaction", () => {
3840

3941
it.only("should send an eip7702 transaction", async () => {
4042
const account = TEST_ACCOUNT_A;
41-
const delegate = privateKeyToAccount({
42-
privateKey: "",
43+
const executor = TEST_ACCOUNT_B;
44+
45+
console.log("ACCOUNT", account.address);
46+
console.log("DELEGATE", executor.address);
47+
48+
const chain = defineChain(911867);
49+
const tokenContract = getContract({
50+
address: "0xAA462a5BE0fc5214507FDB4fB2474a7d5c69065b",
51+
chain,
4352
client: TEST_CLIENT,
4453
});
4554

46-
const chain = defineChain(911867);
55+
const claimTx = claimTo({
56+
contract: tokenContract,
57+
quantityInWei: 1000n,
58+
to: account.address,
59+
});
60+
61+
// const transferTx = transfer({
62+
// contract: tokenContract,
63+
// amountWei: 1000n,
64+
// to: "0x2247d5d238d0f9d37184d8332aE0289d1aD9991b",
65+
// });
66+
4767
console.log(
4868
"BALANCE BEFORE",
4969
await getWalletBalance({
50-
address: delegate.address,
70+
address: account.address,
5171
chain,
5272
client: TEST_CLIENT,
73+
tokenAddress: tokenContract.address,
5374
}),
5475
);
5576

56-
const nonce = await (async () => {
57-
const rpcRequest = getRpcClient({
77+
// const nonce = await (async () => {
78+
// const rpcRequest = getRpcClient({
79+
// chain,
80+
// client: TEST_CLIENT,
81+
// });
82+
// const { eth_getTransactionCount } = await import(
83+
// "../../rpc/actions/eth_getTransactionCount.js"
84+
// );
85+
// return await eth_getTransactionCount(rpcRequest, {
86+
// address: account.address,
87+
// blockTag: "pending",
88+
// });
89+
// })();
90+
91+
// const signedAuthorization = await account.signAuthorization!({
92+
// address: "0x654F42b74885EE6803F403f077bc0409f1066c58",
93+
// chainId: chain.id,
94+
// nonce: BigInt(nonce),
95+
// });
96+
97+
// console.log("SIGNED AUTHORIZATION", signedAuthorization);
98+
99+
const batchSend = prepareContractCall({
100+
contract: getContract({
101+
address: account.address,
58102
chain,
59103
client: TEST_CLIENT,
60-
});
61-
const { eth_getTransactionCount } = await import(
62-
"../../rpc/actions/eth_getTransactionCount.js"
63-
);
64-
return await eth_getTransactionCount(rpcRequest, {
65-
address: account.address,
66-
blockTag: "pending",
67-
});
68-
})();
69-
70-
const signedAuthorization = await account.signAuthorization!({
71-
address: "0x654F42b74885EE6803F403f077bc0409f1066c58",
72-
chainId: chain.id,
73-
nonce: BigInt(nonce),
74-
});
75-
76-
for (let i = 0; i < 2; i++) {
77-
const batchSend = prepareContractCall({
78-
contract: getContract({
79-
address: account.address,
80-
chain,
81-
client: TEST_CLIENT,
82-
}),
83-
method:
84-
"function execute((bytes data, address to, uint256 value)[] calldata calls) external payable",
85-
authorizationList: [
104+
}),
105+
method:
106+
"function execute((bytes data, address to, uint256 value)[] calldata calls) external payable",
107+
// authorizationList: [signedAuthorization],
108+
params: [
109+
[
86110
{
87-
...signedAuthorization,
88-
contractAddress: signedAuthorization.address,
89-
nonce: Number(signedAuthorization.nonce),
90-
r: ox__Hex.fromNumber(signedAuthorization.r),
91-
s: ox__Hex.fromNumber(signedAuthorization.s),
111+
data: await encode(claimTx),
112+
to: tokenContract.address,
113+
value: 0n,
92114
},
93115
],
94-
params: [
95-
[
96-
{
97-
to: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
98-
value: 10000n,
99-
data: "0x",
100-
},
101-
{
102-
to: "0xb4b5fa134b9640B19d6cd980b3808AD9980D7e14",
103-
value: 10000n,
104-
data: "0x",
105-
},
106-
],
107-
],
108-
});
109-
110-
const batchSendResult = await sendAndConfirmTransaction({
111-
account: delegate,
112-
transaction: batchSend,
113-
});
114-
console.log("BATCH SEND RESULT", batchSendResult.transactionHash);
115-
116-
expect(batchSendResult.transactionHash.length).toBe(66);
117-
118-
console.log(
119-
"BALANCE AFTER",
120-
await getWalletBalance({
121-
address: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
122-
chain,
123-
client: TEST_CLIENT,
124-
}),
125-
await getWalletBalance({
126-
address: "0xb4b5fa134b9640B19d6cd980b3808AD9980D7e14",
127-
chain,
128-
client: TEST_CLIENT,
129-
}),
130-
);
131-
}
116+
],
117+
});
118+
119+
const batchSendResult = await sendAndConfirmTransaction({
120+
account: executor,
121+
transaction: batchSend,
122+
});
123+
console.log("BATCH SEND RESULT", batchSendResult.transactionHash);
124+
125+
expect(batchSendResult.transactionHash.length).toBe(66);
126+
127+
console.log(
128+
"BALANCE AFTER",
129+
await getWalletBalance({
130+
address: account.address,
131+
chain,
132+
client: TEST_CLIENT,
133+
tokenAddress: tokenContract.address,
134+
}),
135+
);
132136
});
133137

134138
it("should add transaction to session", async () => {

packages/thirdweb/src/transaction/actions/send-transaction.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ export async function sendTransaction(
194194
transaction: transaction,
195195
from: account,
196196
});
197-
console.log("SERIALIZE", serializableTransaction);
198-
199197
// branch for gasless transactions
200198
if (gasless) {
201199
// lazy load the gasless tx function because it's only needed for gasless transactions

0 commit comments

Comments
 (0)