# BitCoin

### Detecting the Provider

Once ioPay Wallet is installed and running, you should find that ioPay's mobile in-app browser have a `window.ioPay` object available in the developer console.&#x20;

### Method

***requestAccounts()***:  Connect the current account.

#### Returns:

* `Promise` - `string`: address of current account

#### Example:

```
try {
  let accounts = await window.ioPay.requestAccounts();
  console.log('connect success', accounts);
} catch (e) {
  console.log('connect failed');
}
> connect success ['mfaCeWXkqRTPG85mLXMbBZEJRS8b7bw4Kb']
```

### Method

***getPublicKey()***

#### Returns:

* `Promise` - `string`: publicKey

#### Example:

```
try {
  let res = await window.ioPay.getPublicKey();
  console.log(res)
} catch (e) {
  console.log(e);
}
> 0668e8db9f4a2bc19219058467bb12d4c07952da52e71b8d409684c918b4fd1f
```

### Method

#### signMessage <a href="#signmessage" id="signmessage"></a>

```
ioPay.signMessage(msg)
```

**Parameters**

* `msg` - `string`: a string to sign

**Returns**

* `Promise` - `string`: the signature.

**Example:**

```
// sign by ecdsa
try {
  let res = await window.ioPay.signMessage("welcome to ioPay");
  console.log(res)
} catch (e) {}
```

### Method

#### signPsbt <a href="#signpsbt" id="signpsbt"></a>

```
ioPay.signPsbt(psbtHex[, options])
```

This method will traverse all inputs that match the current address to sign.

**Parameters**

* `psbtHex` - `string`: the hex string of psbt to sign
* options
  * `autoFinalized` - `boolean`: whether finalize psbt after signing, default is true
  * `toSignInputs` - `array`:
    * `index` - `number`: which input to sign
    * `address` - `string`: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
    * `publicKey` - `string`: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
    * `sighashTypes` - `number[]`: (optionals) sighashTypes
    * `disableTweakSigner` - `boolean` :(optionals) When signing and unlocking Taproot addresses, the `tweakSigner` is used by default for signature generation. Enabling this allows for signing with the original private key.

**Returns:**

* `Promise` - `string`: the hex string of signed psbt

**Example:**

```
try {
  let res = await window.ioPay.signPsbt(
    "87543231ff53337a....",
    {
        autoFinalized:false,
        toSignInputs:[
          {
            index: 0,
            address: "tb1qtmjmeglfdqphtqq3yq3t6ruq3tvkfx2u6f7n83",
          },
          {
            index: 1,
            publicKey: "76382...83846262f",
            sighashTypes: [1]
          },
          {
            index: 2,
            publicKey: "76382...83846262f",
          }
        ]
    }
  );
  console.log(res)
} catch (e) {
  console.log(e);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iopay.me/bitcoin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
