# BTC
# Bitget Wallet 钱包仅在以下版本支持此功能
Platform | Version | Description |
---|---|---|
Chrome Extension | >=v2.1.1 | mainnet |
App(IOS) | >= 7.3.9 | mainnet |
App(Android) | >= 7.3.9 | mainnet |
Note
部分方法可能会异常,会在新版本支持
Platform | Version | function |
---|---|---|
Chrome Extension | >=v2.2.0 | getBalance, getInscriptions, pushTx |
App(IOS) | >= 8.8.0 | getBalance, getInscriptions, pushTx |
App(Android) | >= 8.8.0 | getBalance, getInscriptions, pushTx |
# 是否安装
const isBitKeepInstalled = !!(window.bitkeep && window.bitkeep.unisat);
1
# requestAccounts
请求连接到钱包
参数
- 无参数
返回值:
- Promise returns string[]:当前账户地址
try {
let accounts = await unisat.requestAccounts();
console.log('connect success', accounts);
} catch (e) {
console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']
1
2
3
4
5
6
7
2
3
4
5
6
7
# getAccounts
获取当前账户地址
参数
- 无参数
返回值:
- Promise - string: 当前账户地址
try {
let res = await unisat.getAccounts();
console.log(res)
} catch (e) {
console.log(e);
}
> ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]
1
2
3
4
5
6
7
2
3
4
5
6
7
# getNetwork
获取当前账户地址
参数
- 无参数
返回值:
- Promise - string:网络。 livenet 和 testnet
try {
let res = await unisat.getNetwork();
console.log(res)
} catch (e) {
console.log(e);
}
> 'livenet'
1
2
3
4
5
6
7
2
3
4
5
6
7
# switchNetwork
切换网络, 请求钱包切换到指定网络
参数:
- network - string: the network. livenet 和 testnet
返回值:
- 无数据
try {
let res = await unisat.switchNetwork("livenet");
console.log(res)
} catch (e) {
console.log(e);
}
> 'livenet'
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# getPublicKey
获取当前用户的公钥
参数
- 无参数
返回:
- Promise - string: 公钥
try {
let res = await unisat.getPublicKey();
console.log(res)
} catch (e) {
console.log(e);
}
> "03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f"
1
2
3
4
5
6
7
2
3
4
5
6
7
# getBalance
获取账户余额
参数
- 无参数
返回:
- Promise - Object
- confirmed - number : 已确认的聪
- unconfirmed - numbet: 还未确认的聪
- total - number: 总的聪
try {
let res = await unisat.getBalance();
console.log(res)
} catch (e) {
console.log(e);
}
> {
"confirmed":0,
"unconfirmed":100000,
"total":100000
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# getInscriptions
获取当前账户的铭文
参数
- 无参数
返回:
- Promise - Object
- total - number : 总数
- list - Object[] :
- inscriptionId - string : 铭文 id
- inscriptionNumber - string : 铭文 数量
- address - string : 铭文地址
- outputValue - string : 铭文输出值
- content - string : 铭文内容url
- contentLength - string : 铭文内容长度
- contentType - number : 铭文内容 类型
- preview - number : 预览链接
- timestamp - number : 铭文出块时间
- offset - number : 铭文偏移量
- genesisTransaction - string : 创世交易的id
- location - string : 当前位置
try {
let res = await unisat.getInscriptions(0,10);
console.log(res)
} catch (e) {
console.log(e);
}
> {
"total":10,
"list":[
{
inscriptionId: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
inscriptionNumber: 959941,
address: 'bc1q8h8s4zd9y0lkrx334aqnj4ykqs220ss735a3gh',
outputValue: 546,
preview: 'https://ordinals.com/preview/6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
content: 'https://ordinals.com/content/6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
contentLength: 53,
contentType: 'text/plain;charset=utf-8',
timestamp: 1680865285,
genesisTransaction: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531',
location: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531:0:0',
output: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531:0',
offset: 0
}
]
}
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
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
# sendBitcoin
发送 Bitcoin
参数
- toAddress - to 地址
- satoshis - 发送的聪数量
- options - object: (可选)
- feeRate - number: :网络资费率
返回
- Promise - string: 交易 ID
try {
let txid = await unisat.sendBitcoin("tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz",1000);
console.log(txid)
} catch (e) {
console.log(e);
}
1
2
3
4
5
6
2
3
4
5
6
# sendInscription
发送 铭文
参数
- address - string: 接受者地址
- inscriptionId - 铭文 id
- options - Object: (可选)
- feeRate - number:网络资费率
返回
- Promise - Object:
- txid - string : 交易ID
try {
let { txid } = await unisat.sendInscription("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0",{feeRate:15});
console.log("send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny",{txid})
} catch (e) {
console.log(e);
}
1
2
3
4
5
6
2
3
4
5
6
# signMessage
签署消息
参数
- msg - string: 要签名的字符串
返回
- Promise - string: 签名结果
// sign by ecdsa
try {
let res = await unisat.signMessage("abcdefghijk123456789");
console.log(res)
} catch (e) {
console.log(e);
}
> G+LrYa7T5dUMDgQduAErw+i6ebK4GqTXYVWIDM+snYk7Yc6LdPitmaqM6j+iJOeID1CsMXOJFpVopvPiHBdulkE=
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# pushTx
广播交易
参数:
- options - Object:
- rawtx - string: tawtx 广播
返回
- Promise - string: 交易ID
try {
let txid = await unisat.pushTx({
rawtx:"0200000000010135bd7d..."
});
console.log(txid)
} catch (e) {
console.log(e);
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# signPsbt
签署 PSBT 该方法将遍历所有与当前地址匹配的输入进行签名。
参数
- psbtHex - string: 要签名的psbt的十六进制字符串
返回
- Promise - string: 签名的psbt的十六进制字符串
try {
let res = await unisat.signPsbt("70736274ff01007d....");
console.log(res)
} catch (e) {
console.log(e);
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# signPsbts
一次签署多个 PSBT 该方法将遍历所有与当前地址匹配的输入进行签名。
参数
- psbtHexs - string[]: 要签名的 psbt 的十六进制字符串
返回
- Promise - string[]: 签名的psbt的十六进制字符串
try {
let res = await unisat.signPsbts(["70736274ff01007d...","70736274ff01007d..."]);
console.log(res)
} catch (e) {
console.log(e);
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# pushPsbt
广播 PSBT
参数:
- psbtHex - string: 要广播的 psbt 的十六进制字符串
返回
- Promise - string: 交易ID
try {
let res = await unisat.pushPsbt("70736274ff01007d....");
console.log(res)
} catch (e) {
console.log(e);
}
1
2
3
4
5
6
7
2
3
4
5
6
7