Skip to content

Commit 9d14058

Browse files
Merge pull request #34 from depatchedmode/v0.11.0
V0.11.0 - transactions
2 parents d338f3a + 8068feb commit 9d14058

File tree

7 files changed

+136
-20
lines changed

7 files changed

+136
-20
lines changed

api/txdata.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { encodeFunctionData } from 'viem';
2+
3+
export default async () => {
4+
try {
5+
// Contract details
6+
const CONTRACT_ADDRESS = '0x8CA328F83387519Eb8B18Ea23fc01bBe92dE2Adc'; // Counter.sol on Base
7+
const abi = [{'inputs':[],'stateMutability':'nonpayable','type':'constructor'},{'inputs':[],'name':'getCurrentCount','outputs':[{'internalType':'uint256','name':'','type':'uint256'}],'stateMutability':'view','type':'function'},{'inputs':[],'name':'incrementCount','outputs':[],'stateMutability':'nonpayable','type':'function'}];
8+
9+
// Encode the transaction data for the incrementCount function
10+
const calldata = encodeFunctionData({
11+
abi: abi,
12+
functionName: 'incrementCount',
13+
args: []
14+
});
15+
16+
const txJson = JSON.stringify(
17+
{
18+
chainId: 'eip155:8453', // base
19+
method: 'eth_sendTransaction',
20+
params: {
21+
abi: abi, // JSON ABI of the function selector and any errors
22+
to: CONTRACT_ADDRESS,
23+
data: calldata,
24+
value: '0',
25+
},
26+
}
27+
)
28+
29+
// Return the transaction details to the client for signing
30+
return new Response(
31+
txJson,
32+
{
33+
status: 200,
34+
headers: {
35+
'Content-Type': 'application/json; charset=utf-8'
36+
},
37+
}
38+
);
39+
} catch (error) {
40+
return new Response(
41+
JSON.stringify({
42+
error: `Failed to process request: ${error.message}`
43+
}),
44+
{
45+
status: 500,
46+
headers: {
47+
'Content-Type': 'application/json; charset=utf-8'
48+
},
49+
}
50+
);
51+
}
52+
};
53+
54+
export const config = {
55+
path: '/txdata'
56+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "simplest-frame",
33
"type": "module",
4-
"version": "0.10.0",
4+
"version": "0.11.0",
55
"dependencies": {
66
"@netlify/blobs": "^6.4.2",
77
"dompurify": "^3.0.8",
8-
"frames.js": "0.13.0",
8+
"frames.js": "0.14.0",
99
"jsdom": "^24.0.0",
1010
"satori": "^0.10.13",
1111
"satori-html": "^0.3.2",

src/frames/count.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ export default {
3838
buttons: [
3939
{
4040
action: 'post',
41-
label: '🫵 Frame me!'
41+
label: '⬅ Back'
4242
},
4343
{
4444
action: 'post',
45-
label: '🎬 View credits'
46-
}
45+
label: '🫵 Frame me!'
46+
},
4747
]
4848
}
4949
},
5050
handleInteraction: async (msg: FrameActionDataParsed) => {
5151
switch (msg.buttonIndex) {
5252
case 1:
53+
return `poster`;
54+
case 2:
5355
await incrementCount();
5456
await setFramer(msg.requesterFid, msg.inputText);
5557
return `count`;
56-
case 2:
57-
return `credits`;
5858
}
5959
},
6060
}

src/frames/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import poster from "./poster.js";
22
import count from "./count.js";
33
import credits from "./credits.js";
44
import mint from "./mint.js";
5+
import transaction from "./transaction.js";
56
import stolen from "./stolen.js";
67

78
export default {
89
count,
910
poster,
1011
credits,
12+
transaction,
1113
mint,
1214
stolen,
1315
}

src/frames/mint.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
buttons: [
1111
{
1212
action: 'post',
13-
label: '⬅ Back'
13+
label: '⬅ Back'
1414
},
1515
{
1616
action: 'mint',
@@ -21,19 +21,15 @@ export default {
2121
tokenId: '1',
2222
})
2323
},
24-
{
25-
action: 'post',
26-
label: '🎬 View credits'
27-
}
2824
]
2925
}
3026
},
3127
handleInteraction: async (msg: FrameActionDataParsed) => {
3228
switch (msg.buttonIndex) {
3329
case 1:
3430
return `poster`;
35-
case 3:
36-
return `credits`;
31+
case 2:
32+
return `mint`;
3733
}
3834
},
3935
}

src/frames/poster.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ export default {
88
buttons: [
99
{
1010
action: 'post',
11-
label: '🔳 State Demo'
11+
label: '🔳 State'
1212
},
1313
{
1414
action: 'post',
15-
label: '🔳 Mint Demo'
15+
label: '🔳 Tx'
16+
},
17+
{
18+
action: 'post',
19+
label: '🔳 Mint'
1620
},
1721
{
1822
action: 'link',
@@ -23,10 +27,13 @@ export default {
2327
}
2428
},
2529
handleInteraction: (msg: FrameActionDataParsed) => {
26-
if (msg.buttonIndex == 1) {
27-
return `count`
28-
} else if (msg.buttonIndex == 2) {
29-
return `mint`
30+
switch (msg.buttonIndex) {
31+
case 1:
32+
return `count`;
33+
case 2:
34+
return `transaction`;
35+
case 3:
36+
return `mint`;
3037
}
3138
},
3239
};

src/frames/transaction.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { FrameActionDataParsed } from 'frames.js';
2+
const html = String.raw;
3+
4+
export default {
5+
name: 'transaction',
6+
render: async () => {
7+
return {
8+
image: html`
9+
<div style="
10+
font-family: 'Redaction';
11+
display: flex;
12+
flex-direction: column;
13+
width: 100vw;
14+
height: 100vh;
15+
color: white;
16+
background: black;
17+
align-items: center;
18+
justify-content: center;
19+
line-height: 1;
20+
gap: 1rem;
21+
">
22+
<div style="font-size: 5em;">
23+
Count Onchain
24+
</div>
25+
<div style="font-size: 2em;">
26+
Visit the contract to see the current count
27+
</div>
28+
</div>`,
29+
buttons: [
30+
{
31+
action: 'post',
32+
label: '⬅ Back'
33+
},
34+
{
35+
action: 'tx',
36+
target: `${process.env.URL}/txdata`,
37+
label: '⬆ Higher'
38+
},
39+
{
40+
action: 'link',
41+
target: 'https://basescan.org/address/0x8ca328f83387519eb8b18ea23fc01bbe92de2adc',
42+
label: 'View Contract'
43+
}
44+
]
45+
}
46+
},
47+
handleInteraction: async (msg: FrameActionDataParsed) => {
48+
switch (msg.buttonIndex) {
49+
case 1:
50+
return `poster`;
51+
case 2:
52+
return `transaction`;
53+
}
54+
},
55+
}

0 commit comments

Comments
 (0)