|
1 | 1 | import { useState } from 'react';
|
| 2 | +import { Buffer } from 'buffer'; |
2 | 3 |
|
3 | 4 | function App() {
|
4 | 5 | const [mnemonic, setMnemonic] = useState('')
|
| 6 | + const [rawTx, setRawTx] = useState('') |
5 | 7 |
|
6 | 8 | const handleCreateWallet = () => {
|
7 |
| - const WalletCore = (window as any).Module; |
8 |
| - const wallet = new WalletCore.HDWallet.create(128, ""); |
9 |
| - |
10 |
| - console.log(wallet.mnemonic()); |
| 9 | + const { HDWallet } = (window as any).Module; |
| 10 | + const wallet = new HDWallet.create(128, ""); |
| 11 | + |
11 | 12 | setMnemonic(wallet.mnemonic());
|
12 | 13 |
|
13 | 14 | wallet.delete();
|
14 | 15 | }
|
15 | 16 |
|
| 17 | + const testSignEthereumTx = () => { |
| 18 | + const TW = (window as any).TW; |
| 19 | + const { HexCoding, AnySigner, CoinType } = (window as any).Module; |
| 20 | + |
| 21 | + const input = TW.Ethereum.Proto.SigningInput.create({ |
| 22 | + toAddress: "0x6b175474e89094c44da98b954eedeac495271d0f", |
| 23 | + chainId: Buffer.from("01", "hex"), |
| 24 | + nonce: Buffer.from("00", "hex"), |
| 25 | + txMode: TW.Ethereum.Proto.TransactionMode.Enveloped, |
| 26 | + maxInclusionFeePerGas: Buffer.from("0077359400", "hex"), |
| 27 | + maxFeePerGas: Buffer.from("00b2d05e00", "hex"), |
| 28 | + gasLimit: Buffer.from("0130B9", "hex"), |
| 29 | + transaction: TW.Ethereum.Proto.Transaction.create({ |
| 30 | + erc20Transfer: TW.Ethereum.Proto.Transaction.ERC20Transfer.create({ |
| 31 | + to: "0x5322b34c88ed0691971bf52a7047448f0f4efc84", |
| 32 | + amount: Buffer.from("1bc16d674ec80000", "hex"), |
| 33 | + }), |
| 34 | + }), |
| 35 | + privateKey: HexCoding.decode( |
| 36 | + "0x608dcb1742bb3fb7aec002074e3420e4fab7d00cced79ccdac53ed5b27138151" |
| 37 | + ), |
| 38 | + }); |
| 39 | + |
| 40 | + const encoded = TW.Ethereum.Proto.SigningInput.encode(input).finish(); |
| 41 | + const outputData = AnySigner.sign(encoded, CoinType.ethereum); |
| 42 | + const output = TW.Ethereum.Proto.SigningOutput.decode(outputData); |
| 43 | + |
| 44 | + setRawTx(HexCoding.encode(output.encoded)); |
| 45 | + } |
| 46 | + |
16 | 47 | return (
|
17 | 48 | <div>
|
18 | 49 | <button onClick={handleCreateWallet}>Create Wallet</button>
|
19 | 50 | <div>Mnemonic: {mnemonic}</div>
|
| 51 | + <button onClick={testSignEthereumTx}>Signing Ethereum tx</button> |
| 52 | + <div>Raw tx: {rawTx}</div> |
20 | 53 | </div>
|
21 | 54 | );
|
22 | 55 | }
|
|
0 commit comments