forked from MetaMask/metamask-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendTransaction.vue
69 lines (68 loc) · 1.89 KB
/
SendTransaction.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<div>
<button type="button" class="btn primaryBtn" @click="getAccount()">
Enable Ethereum
</button>
<button type="button" class="btn greenBtn" @click="sendEthTransaction()">Send Eth</button>
<transition name="fade">
<div class="feedback" v-if="show_feedback">
<div v-if="show_account">
<strong>Account: </strong><span style="font-family: monospace;">{{ ethAccount }}</span>
</div>
<div v-if="show_tx_result">
<strong>Result: </strong><span style="font-family: monospace;">{{ tx_result }}</span>
</div>
</div>
</transition>
</div>
</template>
<script>
import EthConnectButton from "./EthConnectButton";
export default {
components: {
EthConnectButton,
},
data() {
return {
accounts: [],
tx_result: null,
show_feedback: false,
show_account: false,
show_tx_result: false,
};
},
methods: {
async getAccount() {
const accounts = await ethereum.request({ method: 'eth_requestAccounts' })
// We currently only ever provide a single account,
// but the array gives us some room to grow.
this.ethAccount = accounts[0]
// Present feedback
this.show_tx_result = false;
this.show_account = true;
this.show_feedback = true;
},
sendEthTransaction() {
ethereum.request({
method: 'eth_sendTransaction',
params: [{
from: this.ethAccount,
to: "0x2f318C334780961FB129D2a6c30D0763d9a5C970",
value: "0x29a2241af62c0000",
gas: '0x2710',
gasPrice: '0x09184e72a000',
}]
})
.then((result) => {
console.log(result);
this.tx_result = result;
// Present feedback
this.show_tx_result = true;
this.show_account = false;
this.show_feedback = true;
})
.catch(console.error);
},
},
};
</script>