yevm-wasm 0.1.0

WebAssembly bindings for YEVM — run pre-broadcast Ethereum transaction simulation entirely in the browser.
Documentation
<!DOCTYPE html>
<html>
<head></head>
<body>
    <table>
        <tr>
            <td>URL</td>
            <td><input id="rpc-url" type="url" value="https://ethereum-rpc.publicnode.com" size="61" /></td>
        </tr>
        <tr>
            <td>TX:</td>
            <td><input id="txn-inp" type="url" value="" size="61" /></td>
        </tr>
        <tr>
            <td><button id="btn-run">submit</button></td>
            <td><button id="btn-rnd">random</button></td>
        </tr>
    </table>
    
    <pre id="out"></pre>

    <script type="module">
        import init, { hello, call, pick, run } from './pkg/yevm_wasm.js';
        await init();

        var running = false;
        async function main() {
            if (running) {
                return;
            }
            running = true;
            document.getElementById("out").textContent = 'running...';

            const url = document.getElementById("rpc-url").value;
            if (url.trim().length === 0) {
                console.warn("URL is empty");
                return;
            }

            const txn = document.getElementById("txn-inp").value;
            if (txn.trim().length === 0) {
                console.warn("tx is empty");
                return;                
            }

            var count = {};
            try {
                console.log('URL', url);
                console.log('txn', txn);
                const stream = await run(url, txn, 1);
                var len = 0;
                let step;
                const t0 = performance.now();
                while ((step = await stream.next()) !== null) {
                    console.log(step);
                    count[step.event.Step.name] = (count[step.event.Step.name] ?? 0) + 1;
                    len += 1;
                }
                const ms = performance.now() - t0;
                console.log('stream ended, len', len);
                let time = 'total ' + len + ' events, took: ' + ms + ' ms\n\n';
                let stat = JSON.stringify(count, null, 2);
                let ret = time + stream.check() + '\n\n' + stat;
                document.getElementById("out").textContent = ret;
            } catch (e) {
                console.error('run failed', e);
            }
            running = false;
        }

        async function random() {
            if (running) {
                return;
            }
            const url = document.getElementById("rpc-url").value;
            if (url.trim().length === 0) {
                console.warn("URL is empty");
                return;
            }
            let hash = await pick(url);
            document.getElementById("txn-inp").value = hash;
        }

        document.getElementById("btn-run").onclick = main;
        document.getElementById("btn-rnd").onclick = random;

        let txn = document.getElementById("txn-inp").value;
        if (txn.trim().length === 0) {
            await random();
        }
        await main();
    </script>
</body>
</html>