Skip to content

AoGlobal/aometamask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aometamask

Install

npm install aometamask -S

Quick Start

main.js

import Vue from "vue";
import aometamask from "aometamask";
import "aometamask/lib/aometamask.css";
Vue.use(aometamask);

template

<aometamask />

Properties

tokenInfo: Object {symbol, decimals} 公链默认币种信息

browserurl: String 区块浏览器地址

Example
<aometamask browserurl="https://hecoinfo.com" :tokenInfo="{
	symbol: "HT",
	decimals: "18"
}" />

Contents

API

1. isMetaMaskInstalled

是否安装了 MetaMask

Returns

Boolean

Example
this.$metamask.isMetaMaskInstalled();

2. isMetaMask

是否 MetaMask

Returns

Boolean

Example
this.$metamask.isMetaMask();

3. connect

连接插件

Returns

Array<string>

Example
this.$metamask.connect().then(console.log);
> ["0x40e5A542087FA4b966209707177b103d158Fd3A4"];

4. getAccount

获取账户

Returns

Array<string>

Example
this.$metamask.getAccount().then(console.log);
> ["0x40e5A542087FA4b966209707177b103d158Fd3A4"];

5. getChainId

获取当前公链 ID

Returns

String

Example
this.$metamask.getChainId().then(console.log);
> '1'

6. getBalance

获取余额

Returns

String

Example
this.$metamask.getBalance().then(console.log);
> '1000000000000000000'

7. onChainChanged

监听公链变化

Parameters

Function

Example
this.$metamask.onChainChanged((chainId) => {
  console.log(chainId);
});

8. onAccountsChanged

监听账户变化

Parameters

Function

Example
this.$metamask.onAccountsChanged((accounts) => {
  console.log(accounts);
});
> ["0x40e5A542087FA4b966209707177b103d158Fd3A4"];

9. onMessage

监听消息

Parameters

Function

Example
this.$metamask.onMessage((message) => {
  console.log(message);
});

10. sendTx

发送交易

Parameters

transactionParameters- Object:

  • chainId: String
  • nonce: String
  • gasPrice: String
  • gas: String
  • from: String
  • to: String
  • value: String
  • data: String
Returns

String

Example
this.$metamask.sendTx({
	from: "0x6c999dbc796102774E7CF2b45eD9097a8C0F4d7A",
	to: "0x867f1469356D37313406b75c461fA057c829c749",
	value: "0xfffffff",
}).then(console.log);
> '0xddf72a5196e9464194a7377fb94831d36875f2d8ebb6f9b4829838b8bcd780ca'

11. callContract

调用合约读的方法

Parameters

contractAddress-String: 合约地址

abi-JSON|Array: 合约ABI

name-String: 调用的合约方法名

params-Array调用的合约方法需要传的参数

Example
this.$metamask.callContract("0x0298c2b32eae4da002a15f36fdf7615bea3da047", abi, 'symbol').then(console.log)

12. sendContract

调用合约写的方法

Parameters

contractAddress-String: 合约地址

abi-JSON|Array: 合约ABI

name-String: 调用的合约方法名

params-Array调用的合约方法需要传的参数

Example
this.$metamask.sendContract("0x0298c2b32eae4da002a15f36fdf7615bea3da047", abi, 'transfer', ["0x867f1469356D37313406b75c461fA057c829c749", "0x1232889"]).then(console.log)

13. onTxHash

监听交易

Parameters

txHash- String: 交易 hash

Example
this.$metamask.onTxHash('0xddf72a5196e9464194a7377fb94831d36875f2d8ebb6f9b4829838b8bcd780ca').then(console.log)
> {
	from: "0x...",
	to: "0x...",
	tansactionHash: "0x...",
	status: 1,
	blockHash: "0x...",
	blockNumber: 5388714,
	.....
}

14. getTxRecord

获取交易记录

Returns

Array:

  • address: String 地址
  • chainId: String 公链 ID
  • txHash: String 交易 hash
  • status: String 交易状态 pending | success | failed
Example
this.$metamask.getTxRecord().then(console.log) >
  [{ from, to, chainId, txHash, status }];

15. getPendingTxRecord

获取 pending 状态交易记录

Returns

Array:

  • address: String 地址
  • chainId: String 公链 ID
  • txHash: String 交易 hash
  • status: String 交易状态 pending
Example
this.$metamask.getPendingTxRecord().then(console.log) >
  [{ from, to, chainId, txHash, status: "pending" }];

16. clearTxRecord

获取 pending 状态交易记录

Example
this.$metamask.clearTxRecord();

17. onTxStatusChange

监听交易状态的变化

Parameters

Function

Example
this.$metamask.onTxStatusChange((list) => {
  console.log(list); // 交易记录
});

About

the metamask plugin on vuejs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages