Kaspa integration

Welcome to KasWare's integration documentation. This documentation is for learning to integrate KasWare wallet with your applications. Please note : The integration API may be modified if relevant standards are officially released by kaspa core team one day in the future.

Getting Started

First of all, install KasWare Wallet on your development machine. Once KasWare Wallet is installed and running, you should find that new browser tabs have a window.kasware object available in the developer console. This is how your website will interact with KasWare Wallet.

Demo Code

Demo source code

Browser Detection

To verify if the browser is running KasWare Wallet, copy and paste the code snippet below in the developer console of your web browser:

if (typeof window.kasware !== "undefined") {
  console.log("KasWare Wallet is installed!");
}

You can review the full API for the window.kasware object here.

Connecting to KasWare Wallet

"Connecting" or "logging in" to KasWare Wallet effectively means "to access the user's Kaspa account(s)".

You should only initiate a connection request in response to 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 KasWare Wallet to your dapp. Clicking this button should call the following method:

​​

Methods

requestAccounts

Connect the current account.

Parameters

none

Returns

  • Promise returns string[] : Address of current account.

Example

getAccounts

Get address of current account. It's also used to certify if the user is connected, which should be called first.

Parameters

none

Returns

  • Promise - string: address of current account

Example

getVersion

get wallet version

Parameters

none

Returns

  • Promise - string: wallet version

Example

getNetwork

get network

Parameters

none

Returns

  • Promise - string: the network. livenet and testnet

Example

switchNetwork

switch network It's disable in the mobile app.

Parameters

  • network - string: the network. mainnet/testnet/devnet

Returns

none

Example

disconnect

disconnect kasware wallet

Parameters

  • origin - string: website origin url

Returns

none

Example

getPublicKey

Get publicKey of current account.

Parameters

none

Returns

  • Promise - string: publicKey

Example

getBalance

Get KAS balance

Parameters

none

Returns

  • Promise - Object:

    • confirmed - number : the confirmed sompi

    • unconfirmed - number : the unconfirmed sompi

    • total - number : the total sompi

Example

getKRC20Balance

Get KRC20 token balance

Parameters

none

Returns

  • Promise - Array of Object:

    • balance: string;

    • dec: string;

    • locked: string;

    • opScoreMod: string;

    • tick: string;

Example

getUtxoEntries

Get UTXO entries

Parameters

none

Returns

  • Promise - Array of Object:

Example

sendKaspa

Send KAS

Parameters

  • toAddress - string: the address to send

  • sompi - number: the sompi to send

  • options - object: (optional)

    • priorityFee - number: the network prioity fee. default is 0. Unit is sompi

    • payload - string: payload for transactions

Returns

  • Promise - string: txid

Example

signPskt

sign Pskt

Parameters

  • txJsonString - string: a pskt json string

  • options - object:

    • signInputs - object array.

      • index - number: index of input to sign

      • sighashType - number: the sighash type.

Returns

  • Promise - string: signed tx json string

Example

buildScript

build inscription script

Parameters

  • type - string: script type. "KRC20" | "KNS" | "KSPR_KRC721"

  • data - string: the data to inscribe

Returns

  • Promise - object: inscription string and p2sh address

Example

submitCommitReveal

Demo Code For submitCommitReveal

Demo Code For KRC20 Marketplace

Demo Code For KRC20 Marketplace

createKRC20Order

Create a KRC20 Order to sell KRC20 token

Parameters

  • krc20Tick - string: krc20 token tick

  • krc20Amount - number || string: the amount of KRC20 token to sell, Unit is KRC20 token

  • kasAmount - number: total selling price. Unit is kas

  • psktExtraOutput - {address:string; amount: number }[]:(optional) use psktExtraOutput to create a service fee or other things

  • priorityFee - number:(optional) the network prioity fee. default is 0. Unit is kas.

Returns

  • Promise - { txJsonString: string, sendCommitTxId:string }: txJsonString is the pskt json string, sendCommitTxId is the commit transaction id of Send OP

Example:

buyKRC20Token

Demo Code For buyKRC20Token()

Parameters

  • txJsonString - string: a pskt json string from the createKRC20Order() function

  • extraOutput - {address:string; amount: number }[]: (optional) use extraOutput to create a service fee or other things

  • priorityFee - number: (optional) the network prioity fee. default is 0. Unit is kas.

Returns

  • Promise - txId: transaction id

cancelKRC20Order

Demo Code For cancelKRC20Order()

Parameters

  • krc20Tick - string: krc20 token tick

  • txJsonString - string: (optional) a pskt json string from the createKRC20Order() function

  • sendCommitTxId - string: (optional) sendCommitTxId is the commit transaction id of Send OP from the createKRC20Order() function

Returns

  • Promise - txId: transaction id

signMessage

Demo Code For signMessage()

sign message

Parameters

  • msg - string: a string to sign

  • type - string: (Optional) "auto" | "schnorr" | "ecdsa". default is "auto"

  • noAuxRand - boolean: (Optional) if true, do not use aux rand. default is false

Returns

  • Promise - string: the signature.

Example

signKRC20Transaction

Sign KRC20 Transaction

Parameters

  • inscribeJsonString - string: stringified json object

  • type - number: 2 for deployment, 3 for mint, 4 for transfer

  • destAddr - string:(optional) the address to transfer. it's an optional parameter. only used for transfer

  • priorityFee - number:(optional) the network prioity fee. default is 0. Unit is kas.

Returns

  • Promise - string: txid

Example-1: deploy a KRC20 token

Example-2: mint a KRC20 token

Example-3: transfer a KRC20 token

Events

accountsChanged

The accountsChanged will be emitted whenever the user's exposed account address changes.

networkChanged

The networkChanged will be emitted whenever the user's network changes.

balanceChanged

The balaneChanged will be emitted whenever the user's balance changes.

Example

transactionReplacementResponse

The transactionReplacementResponse will be emitted whenever the user pushes a rbf transaction.

Example

Last updated