Skip to content

Commit 092ff6c

Browse files
committed
feat: add example Tempo batch tx
1 parent 96b689d commit 092ff6c

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import globalContext from '../..';
2+
3+
// Tempo Transactions
4+
5+
// ERC20 TST token created and owned by shared account 0x13b7e6EBcd40777099E4c45d407745aB2de1D1F8
6+
const erc20TokenAddress = '0x86fA047df5b69df0CBD6dF566F1468756dCF339D';
7+
const chainId = '0x89'; // Forcing to Polygon PoS for now since EIP7702 not available on Tempo
8+
const feeToken = '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+
22+
<button
23+
class="btn btn-primary btn-lg btn-block mb-3"
24+
id="sendTempoBatchTx"
25+
disabled
26+
>
27+
Send Tempo (0x76) Batch Transaction
28+
</button>
29+
<p>Sends a minimalistic 0x76 batch with 2 ERC20 transfers on chain ${chainId} for initial testing:</p>
30+
<ul>
31+
<li>0.01 TST to 0x2367e6eca6e1fcc2d112133c896e3bddad375aff</li>
32+
<li>0.01 TST to 0x1e3abc74428056924cEeE2F45f060879c3F063ed</li>
33+
</ul>
34+
<p>TST address: ${erc20TokenAddress}</p>
35+
<p>'feeToken' set to ${feeToken}</p>
36+
<p class="info-text alert alert-warning">
37+
Result:
38+
<span id="sendTempoBatchTxResult"></span>
39+
</p>
40+
</div>
41+
</div>
42+
</div>`,
43+
);
44+
45+
const sendTempoBatchTx = document.getElementById('sendTempoBatchTx');
46+
47+
const sendTempoBatchTxResult = document.getElementById(
48+
'sendTempoBatchTxResult',
49+
);
50+
51+
document.addEventListener('globalConnectionChange', function (e) {
52+
if (e.detail.connected) {
53+
sendTempoBatchTx.disabled = false;
54+
}
55+
});
56+
57+
document.addEventListener('disableAndClear', function () {
58+
sendTempoBatchTx.disabled = true;
59+
});
60+
61+
/**
62+
* Send as would be sent by Viem Tempo implementation for dApps
63+
*/
64+
sendTempoBatchTx.onclick = async () => {
65+
try {
66+
const from = globalContext.accounts[0];
67+
// As sent by some Tempo example dapps
68+
const send = await globalContext.provider.request({
69+
method: 'eth_sendTransaction',
70+
params: [
71+
{
72+
calls: [
73+
{
74+
data: '0xa9059cbb0000000000000000000000002367e6eca6e1fcc2d112133c896e3bddad375aff000000000000000000000000000000000000000000000000002386f26fc10000',
75+
to: erc20TokenAddress,
76+
value: '0x',
77+
},
78+
{
79+
data: '0xa9059cbb0000000000000000000000001e3abc74428056924ceee2f45f060879c3f063ed000000000000000000000000000000000000000000000000002386f26fc10000',
80+
to: erc20TokenAddress,
81+
value: '0x',
82+
},
83+
],
84+
chainId,
85+
feeToken,
86+
from,
87+
type: '0x76', // Tempo in-house tx type.
88+
},
89+
],
90+
});
91+
sendTempoBatchTxResult.innerHTML = send;
92+
} catch (err) {
93+
console.error(err);
94+
sendTempoBatchTxResult.innerHTML = `Error: ${err.message}`;
95+
}
96+
};
97+
}

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)