GoSat Wallet API
Welcome to GoSat's Developer Documentation. This documentation is for learning to develop applications for GoSat Wallet.
To develop for GoSat Wallet, install GoSat Wallet on your development machine.
Once GoSat Wallet is installed and running, you should find that new browser tabs have an
window.gosat
object available in the developer console. This is how your website will interact with GoSat Wallet.To verify if the browser is running GoSat Wallet, copy and paste the code snippet below in the developer console of your web browser:
if (typeof window.gosat !== 'undefined') {
console.log('GoSat Wallet is installed!');
}
You can review the full API for the
window.gosat
object here."Connecting" or "logging in" to GoSat Wallet effectively means "to access the user's Bitcoin account(s)".
You should only initiate a connection request in response to a direct user action, such as clicking a button. You should always disable the "connect" button while the connection request is pending. You should never initiate a connection request on page load.
We recommend that you provide a button to allow the user to connect GoSat Wallet to your DAPP. Clicking this button should call the following method:
gosat.requestAccounts()
gosat.requestAccounts()
Connect the current account.
Parameters
none
Returns
Promise
returns string[]
: Address of current account.Example
try {
let accounts = await window.gosat.requestAccounts();
console.log('connect success', accounts);
} catch (e) {
console.log('connect failed');
}
> connect success ['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz']
gosat.getAccounts()
Get address of current account
Parameters
none
Returns
Promise
-string
: address of current account
Example
try {
let res = await window.gosat.getAccounts();
console.log(res)
} catch (e) {
console.log(e);
}
> ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]
gosat.getNetwork()
get network
Parameters
none
Returns
Promise
-string
: the network.livenet
andtestnet
Example
try {
let res = await window.gosat.getNetwork();
console.log(res)
} catch (e) {
console.log(e);
}
> 0
gosat.switchNetwork(network)
switch network
Parameters
network
-string
: the network.livenet
andtestnet
Returns
none
Example
try {
let res = await window.gosat.switchNetwork("livenet");
console.log(res)
} catch (e) {
console.log(e);
}
> 0
gosat.getPublicKey()
Get publicKey of the current account.
Parameters
none
Returns
Promise
-string
: publicKey
Example
try {
let res = await window.gosat.getPublicKey();
console.log(res)
} catch (e) {
console.log(e);
}
> 03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f
gosat.getBalance()
Get BTC balance
Parameters
none
Returns
Promise
-Object
:confirmed
-number
: the confirmed satoshisunconfirmed
-number
: the unconfirmed satoshistotal
-number
: the total satoshis
Example
try {
let res = await window.gosat.getBalance();
console.log(res)
} catch (e) {
console.log(e);
}
> {
"confirmed":0,
"unconfirmed":100000,
"total":100000
}
gosat.getInscriptions(cursor,size)
List inscriptions of current account
Parameters
none
Returns
Promise
-Object
:total
-number
: the total countlist
-Object[]
:inscriptionId
-string
: the id of inscription.inscriptionNumber
-string
: the number of inscription.address
-string
: the address of inscription.outputValue
-string
: the output value of inscription.content
-string
: the content url of inscription.contentLength
-string
: the content length of inscription.contentType
-number
: the content type of inscription.preview
-number
: the preview linktimestamp
-number
: the blocktime of inscription.offset
-number
: the offset of inscription.genesisTransaction
-string
: the txid of genesis transactionlocation
-string
: the txid and vout of current location
Example
try {
let res = await window.gosat.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
}
]
}
gosat.sendBitcoin(toAddress, satoshis, options)
Send BTC
Parameters
toAddress
-string
: the address to sendsatoshis
-number
: the satoshis to sendoptions
-object
:feeRate
-number
: the network fee rate
Returns
Promise
-string
: txid
Example
try {
let txid = await window.gosat.sendBitcoin("tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz",1000);
console.log(txid)
} catch (e) {
console.log(e);
}
gosat.sendInscription(address, inscriptionId, options)
Send Inscription
Parameters
options
-Object
:id
-string
: the id of Inscription.address
-string
: the receiver address.
Returns
Promise
-Object
:txid
-string
: the txid
Example
try {
let {txid} = await window.gosat.sendInscription("tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny","e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0");
console.log("send Inscription 204 to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny",{txid})
} catch (e) {
console.log(e);
}
gosat.signMessage(msg[, address])
sign message
Parameters
msg
-string
: a string to sign
Returns
Promise
-string
: the signature.
Example
try {
let res = await window.gosat.signMessage("abcdefghijk123456789");
console.log(res)
} catch (e) {
console.log(e);
}
> IMEo3yzgqJKlmc38IqlP3YjadVOnXmVR6fqeDhtVdiyHUbitYlO2CFUHUgGtM1/cjWsWoGVhTv6pyvj9L/kNT5A=
gosat.pushTx(options)
Push Transaction
Parameters
options
-Object
:rawtx
-string
: rawtx to push
Returns
Promise
-string
: txid
Example
try {
let txid = await window.gosat.pushTx({
rawtx:"0200000000010135bd7d..."
});
console.log(txid)
} catch (e) {
console.log(e);
}
gosat.signPsbt(psbtHex)
Sign PSBT
This method will traverse all inputs that match the current address to sign.
Parameters
psbtHex
-string
: the hex string of psbt to sign
Returns
Promise
-string
: the hex string of signed psbt
Example
try {
let res = await window.gosat.signPsbt("70736274ff01007d....");
console.log(res)
} catch (e) {
console.log(e);
}
gosat.pushPsbt(psbtHex)
Push transaction
Parameters
psbtHex
-string
: the hex string of psbt to push
Returns
Promise
-string
: txid
Example
try {
let res = await window.gosat.pushPsbt("70736274ff01007d....");
console.log(res)
} catch (e) {
console.log(e);
}
gosat.on('accountsChanged', handler: (accounts: Array<string>) => void);
gosat.removeListener('accountsChanged', handler: (accounts: Array<string>) => void);
The
accountsChanged
will be emitted whenever the user's exposed account address changes.gosat.on('networkChanged', handler: (network: string) => void);
gosat.removeListener('networkChanged', handler: (network: string) => void);
The
networkChanged
will be emitted whenever the user's network changes.Last modified 23d ago