> For the complete documentation index, see [llms.txt](https://lumibit.gitbook.io/lumibit-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lumibit.gitbook.io/lumibit-gitbook/development-guide/typescript-sdk.md).

# TypeScript SDK

{% hint style="warning" %}
We are upgrading our SDK from Devnet to Testnet. Stay tuned for updates!
{% endhint %}

### Devnet Configuration

* ChainId: `28206`
* RPC: `https://rpc.testnet.lumibit.xyz`
* Explorer:  <https://scan.testnet.lumibit.xyz/>

### Usage

1. Add dependencies: `yarn add @lumibit/ethers`&#x20;

### Signer & Provider

```typescript
import {BTCNetwork, JsonRpcProvider, Wallet} from "@lumibit/ethers"


async function main() {
    const provider = new JsonRpcProvider('https://rpc.devnet.lumibit.xyz', BTCNetwork.Testnet)
    const signer = new Wallet(PRIVATE_KEY, provider)
}

main()
```

### Send Transaction

```typescript
// simple transfer
   const btcAddress = await signer.btcAddress
   const tx = await signer.sendTransaction({
            from: wallet.address,
            to: btcAddress,
            value: parseEthers("1"),
   })
   await tx.wait()
//...
```

### Interact with Contract

<pre class="language-typescript"><code class="lang-typescript"><strong>import {Contract, Wallet, BTCNetwork, JsonRpcProvider} from "@lumibit/ethers";
</strong>import {ERC20_ABI, PRIVATE_KEY, USDC_ADDRESS} from "./constants";

//... main()
const provider = new JsonRpcProvider('https://rpc.devnet.lumibit.xyz', BTCNetwork.Testnet)
const signer = new Wallet(PRIVATE_KEY, provider)
const contract = new Contract(USDC_ADDRESS, ERC20_ABI, signer)
const walletAddress = await signer.getAddress()
console.log(`TotalSupply: ${await contract.balanceOf(walletAddress)}`) // Call to any function just like using ethers
await contract.transfer(walletAddress, 10n) // Call to transfer

<strong>//...
</strong></code></pre>

### Deploy Contract

```typescript
mport {Contract, Wallet, BTCNetwork,ContractFactory, JsonRpcProvider} from "@lumibit/ethers";
import {ERC20_ABI, PRIVATE_KEY, USDC_ADDRESS} from "./constants"
// main
const provider = new JsonRpcProvider('https://rpc.devnet.lumibit.xyz', BTCNetwork.Testnet)
const signer = new Wallet(PRIVATE_KEY, provider)
const abi = [
  "constructor(uint totalSupply)"
];
const bytecode = "0x608060405234801561001057600080fd5b506040516103bc3803806103bc83398101604081905261002f9161007c565b60405181815233906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a333600090815260208190526040902055610094565b60006020828403121561008d578081fd5b5051919050565b610319806100a36000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063313ce5671461005157806370a082311461006557806395d89b411461009c578063a9059cbb146100c5575b600080fd5b604051601281526020015b60405180910390f35b61008e610073366004610201565b6001600160a01b031660009081526020819052604090205490565b60405190815260200161005c565b604080518082018252600781526626bcaa37b5b2b760c91b6020820152905161005c919061024b565b6100d86100d3366004610222565b6100e8565b604051901515815260200161005c565b3360009081526020819052604081205482111561014b5760405162461bcd60e51b815260206004820152601a60248201527f696e73756666696369656e7420746f6b656e2062616c616e6365000000000000604482015260640160405180910390fd5b336000908152602081905260408120805484929061016a9084906102b6565b90915550506001600160a01b0383166000908152602081905260408120805484929061019790849061029e565b90915550506040518281526001600160a01b0384169033907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a350600192915050565b80356001600160a01b03811681146101fc57600080fd5b919050565b600060208284031215610212578081fd5b61021b826101e5565b9392505050565b60008060408385031215610234578081fd5b61023d836101e5565b946020939093013593505050565b6000602080835283518082850152825b818110156102775785810183015185820160400152820161025b565b818111156102885783604083870101525b50601f01601f1916929092016040019392505050565b600082198211156102b1576102b16102cd565b500190565b6000828210156102c8576102c86102cd565b500390565b634e487b7160e01b600052601160045260246000fdfea2646970667358221220d80384ce584e101c5b92e4ee9b7871262285070dbcd2d71f99601f0f4fcecd2364736f6c63430008040033"
const contractFactory = new ContractFactory(abi, bytecode, signer);
const contract = await contractFactory.deploy(10n);
const res = await contract.deploymentTransaction()?.wait()
expect(res?.status).to.eq(1)
//...
```

### LumiBit Utils

```typescript
import {bech32ToEvmAddress, evmAddressToBech32, toBtcAddress, BTCNetwork} from "@lumibit/ethers"
// Can use those helper function to convert address between bech32 and evm

bech32ToEvmAddress("tb1qhwylftpwqyukaz85t47pwvlccpw6v5kf7a0g4d")
evmAddressToBech32("0x4f1131d79e312ad6802cbdd13c4bf9df09a82678", BTCNetwork.Testnet) // default will be testnet
toBtcAddress("0x4f1131d79e312ad6802cbdd13c4bf9df09a82678", BTCNetwork.Testnet)
```

### Uniswap Deployment Demo

We also provide a **Hardhat Uniswap Deployment** demo to show how to deploy complex contracts in [lumibit](< https://github.com/LumiBitProtocol/uniswap-deployment-demo>)&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://lumibit.gitbook.io/lumibit-gitbook/development-guide/typescript-sdk.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.
