# Sensilet API
# = Basic Methods =
This is an implementation referring to the Web3 standard. The wallet provides the minimum necessary signature method. For usage, please refer to sensible-web3 (opens new window).
# isConnect
sensilet.isConnect()
get the connect state.
# Parameters
none
# Returns
Promise
returns boolean
: Address of current account.
# Example
let isConnected = await window.sensilet.isConnect();
console.log('connect state', isConnected);
> true
# requestAccount
sensilet.requestAccount()
Connect the current account.
# Parameters
none
# Returns
Promise
returns string
: Address of current account.
# Example
try {
let res = await window.sensilet.requestAccount();
console.log('connect success', address);
} catch (e) {
console.log('connect failed');
}
> connect success 1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj
# exitAccount
sensilet.exitAccount()
disconnect account
# Parameters
none
# Returns
none
# Example
try {
await window.sensilet.exitAccount();
} catch (e) {
console.log(e);
}
# transferBsv
sensilet.transferBsv(options)
Transfer BSV
# Parameters
options
-Object
:receivers
-{address : string,amount : number}[]
: bsv receiversbroadcast
-boolean
: (Optional) whether not to broadcast the transaction, the default is true
# Returns
Promise
-string
: txid
# Example
try {
let txid = await window.sensilet.transferBsv({
receivers:[
{
address:"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",
amount:1000
}
]
});
console.log(txid)
} catch (e) {
console.log(e);
}
# transferSensibleFt
sensilet.transferSensibleFt(options)
Transfer token
# Parameters
options
-Object
:codehash
-string
: the codehash of token.genesis
-string
: the genesis of token.receivers
-{address : string,amount : number}[]
: token receiversrabinApis
-{address : string,amount : number}[]
: (Optional) specify the rabinApis of token.broadcast
-boolean
: (Optional) whether not to broadcast the transaction, the default is true
# Returns
Promise
-string
: txid
# Example
try {
let txid = await window.sensilet.transferSensibleFt({
codehash:"777e4dd291059c9f7a0fd563f7204576dcceb791",
genesis:"8e9c53e1a38ff28772db99ee34a23bb305062a1a",
receivers:[
{
address:"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",
amount:"100000"
}
]
});
console.log("transfer 100 OVTS to xxxx",txid)
} catch (e) {
console.log(e);
}
# getBsvBalance
sensilet.getBsvBalance()
Get BSV balance
# Parameters
none
# Returns
Promise
-Object
:address
-string
: the codehash of token.balance
-{confirmed:number, unconfirmed:number, total:number}
# Example
try {
let res = await window.sensilet.getBsvBalance();
console.log(res)
} catch (e) {
console.log(e);
}
> {
"address":"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",
"balance":{
"confirmed":0,
"unconfirmed":100000,
"total":100000
}
}
# getSensibleFtBalance
sensilet.getSensibleFtBalance()
Get token balance
# Parameters
none
# Returns
Promise
-Object[]
:codehash
-string
: the codehash of token.genesis
-string
: the genesis of token.sensibleId
-string
: the sensibleId of token.name
-string
: the name of token.symbol
-string
: the symbol of token.balance
-number
: the confirmed balance of token.pendingBalance
-number
: the unconfirmed balance of token.decimal
-number
: the decimal of token.
# Example
try {
let res = await window.sensilet.getSensibleFtBalance();
console.log(res)
} catch (e) {
console.log(e);
}
> [
{
codehash: '777e4dd291059c9f7a0fd563f7204576dcceb791',
genesis: '8e9c53e1a38ff28772db99ee34a23bb305062a1a',
sensibleId: '17f47c6861b3a4fec7d337d80d204e6d214836c88e49e9bea398feddddb455ae00000000',
name: 'OVTS',
symbol: 'OVTS',
balance: 1000000,
pendingBalance: 1000000,
decimal: 3,
logo: '/img/OVTS.png'
}
]
# signTx
sensilet.signTx(options)
sign transaction
# Parameters
options
-Object
:list
-Object[]
:txHex
-string
:the hex raw transaction to signaddress
-string
: the address of account to signinputIndex
-number
:the index of input to signscriptHex
-string
: the previous output script of inputsatoshis
-number
: the previous output satoshis value of the inputsigtype
-number
: the sighash type
# Returns
Promise
-Object
:publicKey
-string
: the publicKey of account.r
-string
: the R of the signature.s
-string
: the S of the signature.sig
-string
: the signature.
# Example
try {
let res = await window.sensilet.signTx({
list:[
{
txHex:"xxxxxxxxx",
address:"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",
inputIndex:0,
scriptHex:"76a91436521092539d313000ea730def268b522f0c588688ac",
satoshis:30000,
sigtype:65
}
]
});
console.log(res)
} catch (e) {
console.log(e);
}
> {
"sigList": [
{
"publicKey": "026887958bcc4cb6f8c04ea49260f0d10e312c41baf485252953b14724db552aac",
"r": "7d4857743ddd3817039cc4813fc6ea585a6d535dbcd4c2d9864d8afab54acf59",
"s": "380aaecd30f7e86f08917fa21c96958b56d0a0cd91413e4a34cd7fddb4f75587",
"sig": "304402207d4857743ddd3817039cc4813fc6ea585a6d535dbcd4c2d9864d8afab54acf590220380aaecd30f7e86f08917fa21c96958b56d0a0cd91413e4a34cd7fddb4f7558741"
}
]
}
# signMsg
sensilet.signMsg(options)
sign message
# Parameters
options
-Object
:msg
-string
: a string to sign
# Returns
- ``Promise
-
Object`:address
-string
: the address of account.sig
-string
: the signature.
# Example
try {
let res = await window.sensilet.signMsg({
msg:"abcdefghijk123456789"
});
console.log(res)
} catch (e) {
console.log(e);
}
> {
address: '1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj',
sig: 'IMEo3yzgqJKlmc38IqlP3YjadVOnXmVR6fqeDhtVdiyHUbitYlO2CFUHUgGtM1/cjWsWoGVhTv6pyvj9L/kNT5A='
}
# checkTokenUtxoCount
sensilet.checkTokenUtxoCount(options)
Check whether the conditions of the transfer token are met, if not, initiate a merge operation.
# Parameters
options
-Object
:codehash
-string
: the codehash of tokengenesis
-string
: the genesis of token
# Returns
- ``Promise
-
boolean`: Is it possible to transfer
# Example
try {
let res = await window.sensilet.checkTokenUtxoCount({
codehash:"777e4dd291059c9f7a0fd563f7204576dcceb791",
genesis:"8e9c53e1a38ff28772db99ee34a23bb305062a1a"
});
console.log(res)
} catch (e) {
console.log(e);
}
> true
# transferAll
sensilet.transferAll(options)
Transfer BSV
# Parameters
options
-Object
:codehash
-string
: the codehash of token.genesis
-string
: the genesis of token.receivers
-{address : string,amount : number}[]
: token receiversrabinApis
-{address : string,amount : number}[]
: (Optional) specify the rabinApis of token.broadcast
-boolean
: (Optional) whether not to broadcast the transaction, the default is true
# Returns
Promise
-string
: txid
# Example
try {
let txid = await window.sensilet.transferSensibleFt({
codehash:"777e4dd291059c9f7a0fd563f7204576dcceb791",
genesis:"8e9c53e1a38ff28772db99ee34a23bb305062a1a",
receivers:[
{
address:"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",
amount:"100000"
}
]
});
console.log("transfer 100 OVTS to xxxx",txid)
} catch (e) {
console.log(e);
}
# transferNft
sensilet.transferNft(options)
Transfer NFT
# Parameters
options
-Object
:codehash
-string
: the codehash of NFT.genesis
-string
: the genesis of NFT.tokenIndex
-string
: the tokenIndex of NFT.address
-string
: the receiver address.broadcast
-boolean
: (Optional) whether not to broadcast the transaction, the default is true
# Returns
Promise
-Object
:txid
-string
: the txid
# Example
try {
let {txid} = await window.sensilet.transferNft({
codehash:"22519e29424dc4b94b9273b6500ebadad7b9ad02",
genesis:"1a644549f97acc1a33f4e20bd1eff275df99a2bf",
tokenIndex:"1",
address:"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj"
});
console.log("transfer #1 SLIME to 1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",{txid})
} catch (e) {
console.log(e);
}
# listNft
sensilet.listNft(options)
Transfer BSV
# Parameters
options
-Object
:codehash
-string
: the codehash of token.genesis
-string
: the genesis of token.receivers
-{address : string,amount : number}[]
: token receiversrabinApis
-{address : string,amount : number}[]
: (Optional) specify the rabinApis of token.broadcast
-boolean
: (Optional) whether not to broadcast the transaction, the default is true
# Returns
Promise
-string
: txid
# Example
try {
let txid = await window.sensilet.listNft({
codehash:"777e4dd291059c9f7a0fd563f7204576dcceb791",
genesis:"8e9c53e1a38ff28772db99ee34a23bb305062a1a",
receivers:[
{
address:"1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj",
amount:"100000"
}
]
});
console.log("transfer 100 OVTS to xxxx",txid)
} catch (e) {
console.log(e);
}
# = Web3 Methods =
# getAddress
sensilet.getAddress()
Get address of current account
# Parameters
none
# Returns
Promise
-string
: address of current account
# Example
try {
let res = await window.sensilet.getAddress();
console.log(res)
} catch (e) {
console.log(e);
}
> 1F7XgiBcErvnsh54YgwQbhG7Mxp8Mig2Vj
# getPublicKey
sensilet.getPublicKey()
Get publicKey of current account.
# Parameters
none
# Returns
Promise
-string
: publicKey
# Example
try {
let res = await window.sensilet.getPublicKey();
console.log(res)
} catch (e) {
console.log(e);
}
> 03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f
# signTransaction
sensilet.signTransaction(txHex, inputInfos)
Sign transaction
# Parameters
txHex
-string
: the hex raw transaction to signinputInfos
-Object[]
: the inputs to signinputIndex
-number
: the index of inputscriptHex
-string
: the previous output script of inputsatoshis
-number
: the previous output satoshis of inputsighashType
-number
: the sighash typeaddress
-number|string
: the address of account
# Returns
Promise
-SigResult[]
:sig
-string
: the signaturepublicKey
-string
: the publicKey of account
# Example
try {
let res = await window.sensilet.signTransaction("",[]);
console.log(res)
} catch (e) {
console.log(e);
}
# signMessage
sensilet.signMessage(msg[, address])
sign message
# Parameters
msg
-string
: a string to sign
# Returns
Promise
-string
: the signature.
# Example
try {
let res = await window.sensilet.signMessage("abcdefghijk123456789");
console.log(res)
} catch (e) {
console.log(e);
}
> IMEo3yzgqJKlmc38IqlP3YjadVOnXmVR6fqeDhtVdiyHUbitYlO2CFUHUgGtM1/cjWsWoGVhTv6pyvj9L/kNT5A=