Skip to content

Commit bae190b

Browse files
authored
feat: add example Tempo batch tx (#427)
1 parent 9b32e8a commit bae190b

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import globalContext from '../..';
2+
3+
// Tempo Transactions
4+
5+
// ERC20 TST token created and owned by shared account 0x13b7e6EBcd40777099E4c45d407745aB2de1D1F8
6+
const defaultErc20TokenAddress = '0x86fA047df5b69df0CBD6dF566F1468756dCF339D';
7+
const defaultChainId = '0x89'; // Forcing to Polygon PoS for now since EIP7702 not available on Tempo
8+
const defaultFeeToken = '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359'; // USDC Coin (PoS) for Polygon Mainnet testing
9+
10+
export function tempoTransactionsComponent(parentContainer) {
11+
parentContainer.insertAdjacentHTML(
12+
'beforeend',
13+
`<div
14+
class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch"
15+
>
16+
<div class="card full-width">
17+
<div class="card-body">
18+
<h4>
19+
Tempo Transactions
20+
</h4>
21+
<div class="mb-3">
22+
<label for="tempoChainIdInput" class="form-label">Chain ID</label>
23+
<input
24+
type="text"
25+
class="form-control"
26+
id="tempoChainIdInput"
27+
value="${defaultChainId}"
28+
placeholder="${defaultChainId}"
29+
/>
30+
</div>
31+
32+
<div class="mb-3">
33+
<label for="tempoErc20TokenAddressInput" class="form-label">ERC20 Token Address</label>
34+
<input
35+
type="text"
36+
class="form-control"
37+
id="tempoErc20TokenAddressInput"
38+
value="${defaultErc20TokenAddress}"
39+
placeholder="${defaultErc20TokenAddress}"
40+
/>
41+
</div>
42+
43+
<div class="mb-3">
44+
<label for="tempoFeeTokenInput" class="form-label">Fee Token Address</label>
45+
<input
46+
type="text"
47+
class="form-control"
48+
id="tempoFeeTokenInput"
49+
value="${defaultFeeToken}"
50+
placeholder="${defaultFeeToken}"
51+
/>
52+
</div>
53+
<button
54+
class="btn btn-primary btn-lg btn-block mb-3"
55+
id="sendTempoBatchTx"
56+
disabled
57+
>
58+
Send Tempo (0x76) Batch Transaction
59+
</button>
60+
<p>Sends a minimalistic 0x76 batch with 2 ERC20 transfers on chain [chainId] (hex) for initial testing:</p>
61+
<ul>
62+
<li>0.01 [erc20Token] to 0x2367e6eca6e1fcc2d112133c896e3bddad375aff</li>
63+
<li>0.01 [erc20Token] to 0x1e3abc74428056924cEeE2F45f060879c3F063ed</li>
64+
</ul>
65+
<p class="info-text alert alert-warning">
66+
Result:
67+
<span id="sendTempoBatchTxResult"></span>
68+
</p>
69+
</div>
70+
</div>
71+
</div>`,
72+
);
73+
74+
const sendTempoBatchTx = document.getElementById('sendTempoBatchTx');
75+
76+
const sendTempoBatchTxResult = document.getElementById(
77+
'sendTempoBatchTxResult',
78+
);
79+
80+
document.addEventListener('globalConnectionChange', function (e) {
81+
if (e.detail.connected) {
82+
sendTempoBatchTx.disabled = false;
83+
}
84+
});
85+
86+
document.addEventListener('disableAndClear', function () {
87+
sendTempoBatchTx.disabled = true;
88+
});
89+
90+
/**
91+
* Send as would be sent by Viem Tempo implementation for dApps
92+
*/
93+
sendTempoBatchTx.onclick = async () => {
94+
try {
95+
const from = globalContext.accounts[0];
96+
const erc20TokenAddress = document.getElementById(
97+
'tempoErc20TokenAddressInput',
98+
).value;
99+
const chainId = document.getElementById('tempoChainIdInput').value;
100+
const feeToken = document.getElementById('tempoFeeTokenInput').value;
101+
// As sent by some Tempo example dapps
102+
const send = await globalContext.provider.request({
103+
method: 'eth_sendTransaction',
104+
params: [
105+
{
106+
calls: [
107+
{
108+
data: '0xa9059cbb0000000000000000000000002367e6eca6e1fcc2d112133c896e3bddad375aff000000000000000000000000000000000000000000000000002386f26fc10000',
109+
to: erc20TokenAddress,
110+
value: '0x',
111+
},
112+
{
113+
data: '0xa9059cbb0000000000000000000000001e3abc74428056924ceee2f45f060879c3f063ed000000000000000000000000000000000000000000000000002386f26fc10000',
114+
to: erc20TokenAddress,
115+
value: '0x',
116+
},
117+
],
118+
chainId,
119+
feeToken,
120+
from,
121+
type: '0x76', // Tempo in-house tx type.
122+
},
123+
],
124+
});
125+
sendTempoBatchTxResult.innerHTML = send;
126+
} catch (err) {
127+
console.error(err);
128+
sendTempoBatchTxResult.innerHTML = `Error: ${err.message}`;
129+
}
130+
};
131+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
updateCurrentNetworkDisplay,
5454
updateActiveNetworkInModal,
5555
} from './components/connections/networks-helpers';
56+
import { tempoTransactionsComponent } from './components/tempo-transactions/tempo-transactions';
5657

5758
const {
5859
hstBytecode,
@@ -218,6 +219,7 @@ signTypedDataVariantsComponent(signaturesRow);
218219
siweComponent(signaturesRow);
219220
malformedSignaturesComponent(signaturesRow);
220221
malformedTransactionsComponent(signaturesRow);
222+
tempoTransactionsComponent(signaturesRow);
221223

222224
const interactionsSection = document.createElement('section');
223225
mainContainer.appendChild(interactionsSection);

0 commit comments

Comments
 (0)