Skip to content

Instantly share code, notes, and snippets.

@andelf
Created October 23, 2020 10:18
Show Gist options
  • Select an option

  • Save andelf/5e9047aa22d71f75968ab59ca9eb04e4 to your computer and use it in GitHub Desktop.

Select an option

Save andelf/5e9047aa22d71f75968ab59ca9eb04e4 to your computer and use it in GitHub Desktop.
trezor-connect test
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trezor Test</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<!-- <link rel="stylesheet" href="css/styles.css?v=1.0"> -->
<style type="text/css">
button {
margin: 5px;
}
</style>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://connect.trezor.io/8/trezor-connect.js"></script>
<script type="text/javascript">
const handleMessage = () => {
console.log("handleMessage");
};
$(function () {
TrezorConnect.init({
connectSrc: 'https://localhost:8088/',
// debug: true,
lazyLoad: false, // this param will prevent iframe injection until TrezorConnect.method will be called
manifest: {
email: '@xyz.com',
appUrl: 'http://your.application.com',
}
}).then(() => {
console.log('trezor-connect', 'TrezorConnect is ready!');
$("#status").html('设备已连接');
}).catch(error => {
console.log('trezor-connect', 'TrezorConnect init error:' + error);
$("#status").html('设备初始化错误');
});
window.TrezorConnect.on('DEVICE_EVENT', (event) => {
console.log('EEE event', event);
if (event.type === 'device-connect') {
$('#message').text(JSON.stringify(event.payload));
} else if (event.type === 'device-disconnect') {
$("#status").html('设备已断开');
}
});
TrezorConnect.on('UI.ADDRESS_VALIDATION', (event) => {
$('#message').text("请在设备上确认地址");
});
$("#run").click(function () {
console.log("clicked");
TrezorConnect.getAddress({
path: "m/49'/0'/0'/0/0",
}).then(response => {
console.log(response);
});
});
$("#get-address").click(() => {
TrezorConnect.ethereumGetAddress({
path: "m/44'/60'/0'/0/0",
}).then(resp => {
if (resp.success) {
$("#address").text(resp.payload.address);
}
})
});
$('#get-coin').click(() => {
TrezorConnect.getCoinInfo({ coin: 'eth' }).then(console.log);
})
});
</script>
<h1>Trezor Test</h1>
<h2 id="status">初始化中...</h2>
<hr />
<main>
<button id="run">Run</button>
<br />
<label for="get-address" id="address"></label><button id="get-address">Get Address</button>
<br />
<button id="get-coin">Get Coin</button>
</main>
<hr />
<footer>
<pre id="message"></pre>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment