Metalet is an browser extension wallet based on MetaidConnect protocol.
Once you install your Metalet extension wallet in your browser, Metalet will inject an object called metaidwallet
in the window
object of your page.
You can call Metalet apis using window.metaidwallet.{apiName}
You can connect to your Metalet account and perform various operations such as checking your balance, transferring funds, and signing transactions.
There are two types of api actions: authorize
and query
.
- Calling an
authorize
action will pop up a window asking for permission to perform the requested action. - Calling a
query
action will return the requested data directly.
Account-related.
Connect to the active account of Metalet.
Nope.
address
-string
const account =
(await metaidwallet.connect()) >
{
address: '1xxxxxxxx',
}
Checks if the app is currently connected to the active account of Metalet.
Nope.
boolean
;(await metaidwallet.isConnected()) > true
Disconnect. It functions as Logout.
Nope.
status
-'ok'
;(await metaidwallet.disconnect()) >
{
status: 'ok',
}
Get the current network state.
network
-'mainnet' | 'testnet'
;(await metaidwallet.getNetwork()) > { network: 'testnet' }
Switch the network state of the current account.
Nope.
address
-string
status
-'OK'
network
-'mainnet' | 'testnet'
const account =
(await metaidwallet.switchNetwork()) >
{
address: '1xxxxxxxx',
status: 'OK',
network: 'mainnet',
}
getAddress
retrieves the address of the connecting account.
Nope.
address
- string
const address = (await metaidwallet.getAddress()) > '1xxxxxxxxxxxxxxxxxx'
getPublicKey
retrieves the public key of the connecting account.
Nope.
publicKey
- string
const publicKey = (await metaidwallet.getPublicKey()) > 'xxxxxxxthisisapubkeyxxxxx'
getXPublicKey
retrieves the extended public key of the connecting account.
Nope.
xPublicKey
- string
const xPublicKey = (await metaidwallet.getXPublicKey()) > 'xxxxxxxthisisaextendedpubkeyxxxxx'
Native Token - aka. SPACE / BTC and so on…
retrieves the current balance of the connecting account.
Nope.
address
-string
confirmed
-number
, use satoshi as unitunconfirmed
-number
, use satoshi as unittotal
-number
, use satoshi as unit
const balanceInfo =
(await metaidwallet.getBalance()) >
{
address: '1xxxxxxxx',
confirmed: 92316234,
unconfirmed: 0,
total: 92316234,
}
The one-for-all transfer method.
tasks
-TransferOutput[]
genesis?
-string
, required when type is tokencodehash?
-string
, required when type is tokenreceivers
-Reciever[]
amount
-string
, do not pass numeric value here or Metalet will get upset.address
-string
broadcast?
-boolean
, default totrue
res
-TaskResponse[]
id: number
, the chronological index of the task, starts from 1txid: string
txHex: string
routeCheckTxid?: string
, returned when it’s a token transfer transaction.routeCheckTxHex?: string
, returned when it’s a token transfer transaction.
txids
-string[]
broadcasted
-boolean
Let’s sign something.
Sign ONE transaction.
transaction
-TransactionInfo
txHex: string
address: string
inputIndex: number
scriptHex: string
: the previous output script of this inputsatoshis: number
: the previous output satoshis value of this inputsigtype?: number
: the sighash type
signature
-SigInfo
publicKey: string
r: string
s: string
sig: string
sigtype: number
const signTxRes =
(await metaidwallet.signTransaction({
transaction: {
txHex: 'xxxxxxxxx',
address: '1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj',
inputIndex: 0,
scriptHex: '76a91436521092539d313000ea730def268b522f0c588688ac',
satoshis: 30000,
sigtype: 65,
},
})) >
{
signature: {
publicKey: '026887958bcc4cb6f8c04ea49260f0d10e312c41baf485252953b14724db552aac',
r: '7d4857743ddd3817039cc4813fc6ea585a6d535dbcd4c2d9864d8afab54acf59',
s: '380aaecd30f7e86f08917fa21c96958b56d0a0cd91413e4a34cd7fddb4f75587',
sig: '304402207d4857743ddd3817039cc4813fc6ea585a6d535dbcd4c2d9864d8afab54acf590220380aaecd30f7e86f08917fa21c96958b56d0a0cd91413e4a34cd7fddb4f7558741',
},
}
Preview a transaction’s id before it is signed. Use this when you need to construct linear-dependent transactions.
transaction
-TransactionInfo
txHex: string
address: string
inputIndex: number
scriptHex: string
: the previous output script of this inputsatoshis: number
: the previous output satoshis value of this inputsigtype?: number
: the sighash type
txid
:string
const previewTx =
(await metaidwallet.previewTransaction({
transaction: {
txHex: 'xxxxxxxxx',
address: '1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj',
inputIndex: 0,
scriptHex: '76a91436521092539d313000ea730def268b522f0c588688ac',
satoshis: 30000,
sigtype: 65,
},
})) >
{
txid: 'abcthisisatxidjisdg...123',
}
Sign multiple transactions. Returns signed raw transaction list.
transactions
-TransactionInfo[]
txHex: string
address?: string
inputIndex: number
scriptHex: string
: the previous output script of this inputsatoshis: number
: the previous output satoshis value of this inputsigtype?: number
: the sighash typepath?: string
: the sub derive path you are using. Default to0/0
.hasMetaId?: boolean
: if this transaction is a MetaID transaction. If so, the op_return output will also be updated like we update theprevTxId
in the input.dataDependsOn?: number
: the index of the transaction in the list yourOP_RETURN
data is depend on. Required whenhasMetaId
istrue
.
signedTransactions
-Signed[]
txid: string
txHex: string
const signTxRes =
(await metaidwallet.signTransactions({
transactions: [
{
txHex: 'xxxxxxxxx',
address: '1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj',
inputIndex: 0,
scriptHex: '76a91436521092539d313000ea730def268b522f0c588688ac',
satoshis: 30000,
sigtype: 65,
},
{
// Assume that this transaction is dependent on the first one.
// Therefore the prevTxId of this transaction's input might not be accurate.
// This api will automatically recalculate the correct txid for you and replace it accordingly.
txHex: 'xxxxxxxxx',
address: '1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj',
inputIndex: 0,
scriptHex: '76a91436521092539d313000ea730def268b522f0c588688ac',
satoshis: 30000,
sigtype: 65,
path: '0/3',
hasMetaId: true,
},
],
})) >
// If the transactions are dependent, you have to broadcast them sequentially.
{
signedTransactions: [
{
txid: 'xxxxxxxxxx',
txHex: 'xxxxxxxxxx',
},
{
txid: 'xxxxxxxxxx',
txHex: 'xxxxxxxxxx',
},
],
}
Get the balance info of the token.
If no parameter is provided, the function will return all token information owned by the current account.
genesis
-string
, the genesis of the token -optional
codehash
-string
, the codehash of the token -optional
TokenInfo[]
codehash
-string
, the codehash of the tokengenesis
-string
, the genesis of the tokenname
-string
symbol
-string
decimal
-number
utxoCount
-number
, the utxo count of this token the account ownedconfirmed
-number
confirmedString
-string
unconfirmed
-number
unconfirmedString
-string
const balanceInfo = await metaidwallet.token.getBalance()
> [
{
"codehash": "a2421f1e90c6048c36745edd44fad682e8644693",
"genesis": "039032ade3d49a6d4ff41c33b3d63ea5c986f310",
"name": "Test Token - 20:39",
"symbol": "RR",
"decimal": 18,
"utxoCount": 2,
****"confirmed": 1000,
"confirmedString": "1000",
"unconfirmed": 0,
"unconfirmedString": "0"
},
{
"codehash": "57344f46cc0d0c8dfea7af3300b1b3a0f4216c04",
"genesis": "76a8a2122b4f4213921cb0b4de0e7c704628f149",
"name": "SPACE-MIT",
"symbol": "SMIT",
"decimal": 8,
"utxoCount": 1,
"confirmed": 19000009847,
"confirmedString": "19000009847",
"unconfirmed": 0,
"unconfirmedString": "0"
}
]
Use metaidwallet.on
API to attach your event handler to these events.
// attach an event listener to `accountsChanged` event
metaidwallet.on('accountsChanged', (newAccount) => console.log(newAccount)) >
{
mvcAddress: '1kdiyourmvcaddress234',
btcAddress: 'bc1pyourbtcaddress234',
}
// remove the event listener
metaidwallet.removeListener('accountsChanged')
// attach an event listener to `networkChanged` event
metaidwallet.on('networkChanged', (network: string) => console.log(network)) > 'mainnet'
// remove the event listener
metaidwallet.removeListener('networkChanged')
These APIs are going to be deprecated in the future.
Connect to the active account of Metalet.
Nope.
address
-string
const account =
(await metaidwallet.requestAccount()) >
{
address: '1xxxxxxxx',
}
Connect to the active account of Metalet.
Nope.
address
-string
const account =
(await metaidwallet.getAccount()) >
{
address: '1xxxxxxxx',
}
Nope.
status
-'ok'
;(await metaidwallet.exitAccount()) >
{
status: 'ok',
}
const balanceInfo =
(await metaidwallet.getMvcBalance()) >
{
address: '1xxxxxxxx',
confirmed: 92316234,
unconfirmed: 0,
total: 92316234,
}
Sign transactions.
list
-TransactionInfo[]
txHex: string
address: string
inputIndex: number
scriptHex: string
: the previous output script of this inputsatoshis: number
: the previous output satoshis value of this inputsigtype: number
: the sighash type
sigList
-SigInfo[]
publicKey: string
r: string
s: string
sig: string
const signTxRes =
(await metaidwallet.signTx({
list: [
{
txHex: 'xxxxxxxxx',
address: '1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj',
inputIndex: 0,
scriptHex: '76a91436521092539d313000ea730def268b522f0c588688ac',
satoshis: 30000,
sigtype: 65,
},
],
})) >
{
sigList: [
{
publicKey: '026887958bcc4cb6f8c04ea49260f0d10e312c41baf485252953b14724db552aac',
r: '7d4857743ddd3817039cc4813fc6ea585a6d535dbcd4c2d9864d8afab54acf59',
s: '380aaecd30f7e86f08917fa21c96958b56d0a0cd91413e4a34cd7fddb4f75587',
sig: '304402207d4857743ddd3817039cc4813fc6ea585a6d535dbcd4c2d9864d8afab54acf590220380aaecd30f7e86f08917fa21c96958b56d0a0cd91413e4a34cd7fddb4f7558741',
},
],
}