Threshold Network 백서

Threshold Network

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 36쪽 중 7쪽

eth (GoEthereum). The Ethereum Key File is expected to be encrypted with a password. The password has to be provided in a prompt after the client starts or configured as a `KEEP_ETHEREUM_PASSWORD` environment variable. The Operator Account has to maintain a positive Ether balance at all times.&#x20; {% hint style="warning" %} Please do NOT reuse an operator account that is being used for PRE or other applications.&#x20; {% endhint %} ## Install Geth (GoEthereum) To create a new Ethereum account, [install Geth](https://geth.ethereum.org/docs/install-and-build/installing-geth#ubuntu-via-ppas) (GoEthereum) and create a new account using the command below. This account will subsequently be referred to as the Operator Account. <pre class="language-bash"><code class="lang-bash"><strong>geth account new --keystore ./operator-key </strong></code></pre> When prompted, provide a password to protect the operator key file.&#x20; {% hint style="info" %} Use a password manager to generate a strong password and store it safely. It will be needed again during setup. {% endhint %} {% hint style="warning" %} Avoid passwords that contain the following characters: ', ", \`, $\ These characters may be interpreted as part of the configuration, which can lead to undesirable outcomes that may be extremely time-intensive to correct. {% endhint %} Once the process completes, your public key will be displayed. Take note of your Operator Account public key. {% hint style="danger" %} DO NOT LOSE THE PASSWORD TO THE OPERATOR ACCOUNT. {% endhint %} ### Funding your Operator Account Your Operator Account will need to be funded with sepolia ETH and maintain a positive balance at all times to ensure proper operation and availability of your tBTC v2 node. ## Network Configuration The node has to be accessible publicly to establish and maintain connections with bootstrap nodes and discovered peers. {% hint style="info" %} Update firewall rules as necessary, including application level firewalls. {% endhint %} The node exposes metrics and diagnostics services for monitoring. A network port has to be exposed publicly, so the peers can connect to your node. A Diagnostics Port has to be exposed publicly, for the rewards allocation. | Purpose | Config Property | Protocol | Default | | ------- | --------------- | -------- | ------- | | Network | network.port | TCP | 3919 | | Status | clientInfo.port | TCP | 9601 | {% hint style="info" %} A Diagnostics Port has to be exposed publicly for the rewards allocation. {% endhint %} ### **Announced Addresses** An Announced Address is a layered addressing information (`multiaddress`/`multiaddr`) announced to the Threshold Network that is used by peers to connect with your node, e.g.: `/dns4/bootstrap-0.test.keep.network/tcp/3919` or `/ip4/104.154.61.116/tcp/3919`. If the machine you’re running your node on is not exposing a public IP (e.g., it is behind NAT), you should set the `network.AnnouncedAddresses` (flag: `--network.announcedAddresses`) configuration property to an address (`ip4` or `dns4`) under which your node is reachable for the public. To read more about `multiaddress` see the [libp2p documentation](https://docs.libp2p.io/reference/glossary/#multiaddr). ## Create Folder Structure The client requires two persistent directories. These directories will store configuration files and data generated and used by the client. It is highly recommended to create frequent backups of these directories. Loss of these data may be catastrophic and may lead to slashing. {% hint style="warning" %} It is crucial to ensure that the data directory is persisted and backed up regularly. {% endhint %} #### Create folders for tBTC v2 client ```bash cd /home mkdir keep cd keep mkdir storage config ``` The tBTC v2 client will create two subdirectories within the storage directory: `keystore` and `work`. You do not need to create these.&#x20; The `keystore` subdirectory contains sensitive key material data generated by the client. Loosing the `keystore` data is a serious protocol offense and leads to slashing and potentially losing funds. {% hint style="info" %} It is the operator’s responsibility to ensure the keystore data are not lost under any circumstances. {% endhint %} The `work` directory contains data generated by the client that should persist the client restarts or relocations. If the `work` data are lost the client will be able to recreate them, but it is inconvenient due to the time needed for the operation to complete and may lead to losing rewards. ## **Copy Operator keystore file** Assuming [Geth was installed](/tbtc-signer-nodes/tbtc-v2-node-setup/operator-account) for the root user with the command provided in the [Operator Account creation](/tbtc-signer-nodes/tbtc-v2-node-setup/operator-account) step, the operator-key file should be located in the `~/operator-key` directory. ```bash cd ~/operator-key ``` Contained within the `operator-key` directory is the account key file (operator key file), its name will be similar to the following: \ `UTC--2018-11-01T06-23-57.810787758Z--fa3da235947aab49d439f3bcb46effd1a7237e32` **Copy (not move!)** this account key file to the `config` directory created above ```bash ls -la cp name_of_account_key_file /home/keep/config/name_of_account_key_file ``` ## Install Docker Install or update Docker to the latest version. Visit the [Official Docker website](https://docs.docker.com/engine/install/ubuntu/) for detailed instructions. Use the command below to find your installed version if needed: ```bash docker --version ``` ## Docker Launch Script To launch the tBTC v2 client, several configuration flags and environmental values need to be set. For simplicity, a bash script can be used rather than typing or pasting all the flags into the console. Create the launch script: ``` nano keep.sh ``` And paste the following: ```bash # Keep Testnet tBTC v2 Client # # Ethereum endpoint WebSocket URL # This can be a provider such as Infura, Alchemy, Ankr, etc or your own Geth Nodeq # ETHEREUM_WS_URL="wss://sepolia.infura.io/ws/v3/redacted_credentials" # note: only replace characters inside the " ". The Quotation marks must be retained ETHEREUM_WS_URL="<Ethereum API WS URL>" # copied to home/keep/config earlier OPERATOR_KEY_FILE_NAME="<Operator Account keyfile name>" # password set during Operator Account Address creation OPERATOR_KEY_FILE_PASSWORD="<Operator Account keyfile password>" # To configure your node with a Public IP, enter it below. PUBLIC_IP="<PUBLIC_IP_OF_MACHINE>" # Alternatively, you can use DNS. # To configure DNS, modify the last line of the script # and add your DNS in the following format: # /dns4/bootstrap-1.test.keep.network/tcp/3919 # Setup configuration and storage directories # THESE MUST BE PERSISTENT STORAGE CONFIG_DIR="/home/keep/config" STORAGE_DIR="/home/keep/storage" docker run \ --detach \ --restart on-failure \ --volume $CONFIG_DIR:/mnt/keep/config \ --volume $STORAGE_DIR:/mnt/keep/storage \ --env KEEP_ETHEREUM_PASSWORD=$OPERATOR_KEY_FILE_PASSWORD \ --env LOG_LEVEL=info \ --log-opt max-size=100m \ --log-opt max-file=3 \ -p 3919:3919 \ -p 9601:9601 \ us-docker.pkg.dev/keep-test-f3e0/public/keep-client \ start \ --testnet \ --ethereum.url $ETHEREUM_WS_URL \ --ethereum.keyFile /mnt/keep/config/$OPERATOR_KEY_FILE_NAME \ --storage.dir /mnt/keep/storage \ --network.announcedAddresses /ip4/$PUBLIC_IP/tcp/3919 ``` Save and close the file, and make it executable: ```bash sudo chmod +x keep.sh ``` To launch the tBTC v2 client, execute: <pre class="language-bash"><code class="lang-bash"><strong>sudo bash keep.sh </strong></code></pre> {% hint style="info" %} The `--detach` property will prevent the status messages from the client to be printed to the console. Review the Docker logs for detailed status information. {% endhint %} {% hint style="danger" %} The path shown in the example configuration will differ from yours. Make sure it is configured correctly. {% endhint %} ## Client Startup Unless the `--detach` flag was removed from the startup script; there will be no console output. To check your node, retrieve the Docker logs. First, find your Docker instance identification; it'll be a random combination of words, e.g. `stinky_brownie`: ```bash sudo docker ps ``` Use your specific identification and substitute: ``` sudo docker logs stinky_brownie >& /path/to/output/file ``` Scroll down about half a page, and you should see the following: <pre><code><strong> </strong>▓▓▌ ▓▓ ▐▓▓ ▓▓▓▓▓▓▓▓▓▓▌▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▌▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓ ▐▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓ ▐▓▓▓▓▓▌ ▐▓▓▓▓▓▓ ▓▓▓▓▓▓▄▄▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓▄▄▄▄ ▓▓▓▓▓▓▄▄▄▄ ▐▓▓▓▓▓▌ ▐▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▌ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▀▀▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓▀▀▀▀ ▓▓▓▓▓▓▀▀▀▀ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀ ▓▓▓▓▓▓ ▀▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓ ▐▓▓▓▓▓▌ ▓▓▓▓▓▓▓▓▓▓ █▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ Trust math, not hardware. ----------------------------------------------------------------------------------- | Keep Client Node | | | | Version: Version: vX.X.XX (4d745f6d0) | | | | Operator: 0x_your_operator_address | | | | Port: 3919 | | IPs : /ip4/111.222.333.444/tcp/3919/ipfs/redacted | | | | Contracts: | | RandomBeacon : 0x2bA82903B635a96154A515488d2952E86D6adc3A | | WalletRegistry : 0x2363cc10b7680000C02E4a7067A68d1788ffc86F | | TokenStaking : 0x69f962a0fbA5635e84eC94131f9072108E2E4F24 | ----------------------------------------------------------------------------------- </code></pre> Congratulations, your node is up and running.&#x20; # tBTC SDK Build with Bitcoin using Threshold's tBTC SDK tBTC SDK is a TypeScript library that provides effortless access to the fundamental features of the tBTC Bitcoin bridge. The SDK allows developers to integrate tBTC into their own applications and offer the power of trustless tokenized Bitcoin to their users. The SDK documentation consists of the following parts: * [Quickstart](/app-development/tbtc-sdk/quickstart)&#x20; * [Architecture](/app-development/tbtc-sdk/architecture) * [Guides](/app-development/tbtc-sdk/guides) * [API Reference](https://github.com/keep-network/tbtc-v2/tree/main/typescript/api-reference) For a high-level overview of the tBTC protocol, please see the [tBTC Bitcoin Bridge](/tbtc-v2) section. # Quickstart Here you can find instructions explaining how to use the SDK in your own project. ### Installation To install the tBTC SDK in your project, run: {% tabs %} {% tab title="yarn" %} {% code fullWidth="false" %} ```bash yarn add @keep-network/tbtc-v2.ts ``` {% endcode %} {% endtab %} {% tab title="npm" %} ```bash npm i @keep-network/tbtc-v2.ts ``` {% endtab %} {% endtabs %} Please note that you will also need to install the [ethers v5](https://docs.ethers.org/v5) library to initialize a signer or provider. To do so, invoke: {% tabs %} {% tab title="yarn" %} ```bash yarn add ethers@legacy-v5 ``` {% endtab %} {% tab title="npm" %} ```bash npm i ethers@legacy-v5 ``` {% endtab %} {% endtabs %} {% hint style="warning" %} ``` The SDK depends on ethers v5. Proper support for newer ethers versions is not guaranteed right now. ``` {% endhint %} ### Usage Here is a brief example demonstrating the use of the SDK in Ethereum: ```typescript // Import SDK entrypoint component. import { TBTC } from "@keep-network/tbtc-v2.ts" // Create an instance of ethers signer. const signer = (...) // Initialize the SDK for Ethereum only. const sdk = await TBTC.initializeMainnet(signer) // Access SDK features. sdk.deposits.(...) sdk.redemptions.(...) // Access tBTC smart contracts directly. sdk.tbtcContracts.(...) // Access Bitcoin client directly. sdk.bitcoinClient.(...) ``` #### Crosschain Here is a brief example demonstrating the use of the SDK in some L2, e.g. Arbitrum: ```typescript // Import SDK entrypoint component. import { TBTC } from "@keep-network/tbtc-v2.ts" // Create an instance of ethers provider. const ethProvider = (...) // Create an instance of ethers signer. const arbitrumSigner = (...) // Initialize the SDK for Ethereum only. const sdk = await TBTC.initializeMainnet(ethProvider, true) // Initialize it for any L2 (E.g., Arbitrum) await sdk.initializeCrossChain("Arbitrum", arbitrumSigner); // Access SDK features. sdk.deposits.(...) sdk.redemptions.(...) // Access tBTC smart contracts directly. sdk.tbtcContracts.(...) // Access Bitcoin client directly. sdk.bitcoinClient.(...) ``` # Architecture The following diagram presents the architecture of the tBTC SDK and its place in the ecosystem: <figure><img src="https://2518393180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWosjlL4zUGUMlcMfuSAp%2Fuploads%2Fz2G8pFeLD7t4KwhFUYCO%2FtBTC%20SDK%20Architecture%20Diagram.png?alt=media&amp;token=e362dc6b-1f6e-4ff2-8aaa-b0730d508179" alt=""><figcaption></figcaption></figure> As you can see, the SDK consists of several major parts: * `TBTC` component * Feature services * Shared libraries ### `TBTC` component The `TBTC` component is the main entry point to the SDK. It provides different ways to initialize the SDK that are supposed to address the common use cases (see [Initialize SDK](/app-development/tbtc-sdk/guides/initialize-sdk) guide to learn more). Moreover, the `TBTC` component gives access to the SDK core features through feature services as well as low-level direct access to the underlying tBTC smart contracts and Bitcoin network client. ### Feature services The SDK feature services provide seamless access to the core features of the tBTC bridge. The most important features of the SDK are: * **Deposits:** deposit and mint flow for BTC depositors * **Redemptions:** unmint and redeem flow for TBTC redeemers&#x20; * **Maintenance:** authorized maintenance actions for maintainers (e.g. optimistic minting guardians) ### Shared libraries Shared libraries are reusable modules that provide cross-cutting concerns leveraged by multiple feature services and the `TBTC` component. The main shared libraries of the SDK are: * **Bitcoin**: interfaces and utilities necessary to interact with the Bitcoin chain * **Contracts**: chain-agnostic interfaces allowing interaction with tBTC smart contracts * **Electrum**: Electrum-based implementation of the Bitcoin client * **Ethereum**: implementations of tBTC smart contract interfaces for the Ethereum chain * **Utils**: general utility functions # Guides # Initialize SDK Before initializing the tBTC SDK instance in your project, you need to answer the following questions: * What Bitcoin network and which tBTC contracts do you plan to interact with? * Do you want to perform just read-only actions or send transactions as well? Answering those questions will allow initializing the SDK in the right way. The SDK is prepared to handle common use cases but provides some flexibility as well. This guide explains that in detail. ## Specific guides {% hint style="info" %} These guides will show you how to initialize the SDK in mainnet, testnet, crosschain or custom mode. {% endhint %} {% content-ref url="/pages/eoNzev0ciRsjBzGE4Wh7" %} [Ethereum and Bitcoin mainnet](/app-development/tbtc-sdk/guides/initialize-sdk/ethereum-and-bitcoin-mainnet) {% endcontent-ref %} {% content-ref url="/pages/IyyThGGiDlY4l6D21QDf" %} [Ethereum and Bitcoin testnet](/app-development/tbtc-sdk/guides/initialize-sdk/ethereum-and-bitcoin-testnet) {% endcontent-ref %} {% content-ref url="/pages/vzYgTQooYel4wmCBWok2" %} [Crosschain](/app-development/tbtc-sdk/guides/initialize-sdk/crosschain) {% endcontent-ref %} {% content-ref url="/pages/qJOdHUlK5bVgW7WuzWGQ" %} [Custom mode](/app-development/tbtc-sdk/guides/initialize-sdk/custom-mode) {% endcontent-ref %} # Ethereum and Bitcoin mainnet This is the most common case when you want to use the SDK to interact with the tBTC bridge on Ethereum and Bitcoin mainnet. The SDK addresses it by exposing the `TBTC.initializeMainnet` function. That function: * Takes an Ethers signer or provider as a parameter and uses it to interact with tBTC contracts deployed on Ethereum mainnet * Automatically configures an Electrum Bitcoin client to communicate with the Bitcoin mainnet (communication is done through a set of pre-configured Electrum servers) The following code snippet presents the usage of this function: ```typescript import * as ethers from "ethers" import { TBTC } from "@keep-network/tbtc-v2.ts" // Create an Ethers provider. Pass the URL of an Ethereum mainnet node. // For example, Alchemy or Infura. const provider = new ethers.providers.JsonRpcProvider("...") // Create an Ethers signer. Pass the private key and the above provider. const signer = new ethers.Wallet("...", provider) // If you want to initialize the SDK just for read-only actions, it is // enough to pass the provider. const sdkReadonly = await TBTC.initializeMainnet(provider) // If you want to make transactions as well, you have to pass the signer. const sdk = await TBTC.initializeMainnet(signer) ``` {% hint style="info" %} The above code snippet presents just one way of creating an Ethers signer/provider. Please refer [Ethers v5 documentation](https://docs.ethers.org/v5/api) to learn more. {% endhint %} # Ethereum and Bitcoin testnet This is the case where you want to use the SDK to interact with the tBTC bridge on Ethereum and Bitcoin testnet. &#x20;The SDK addresses it by exposing the `TBTC.initializeSepolia` function. That function: * Takes an Ethers signer or provider as a parameter and uses it to interact with tBTC contracts deployed on Ethereum Sepolia * Automatically configures an Electrum Bitcoin client to communicate with the Bitcoin testnet (communication is done through a set of pre-configured Electrum servers) The usage of this function is exactly the same as for the previous `TBTC.initializeMainnet` function. # Crosschain This mode of the SDK will initialize Ethereum, Bitcoin and an L2 to work with tBTC. Compatible with mainnet and testnet. {% hint style="info" %} Currently only functional with **Arbitrum**, soon more blockchains will be available. {% endhint %} ## Mainnet The SDK addresses it by exposing the `TBTC.initializeMainnet` function. That function: * Takes an Ethers signer or provider as a parameter and uses it to interact with tBTC contracts deployed on Ethereum mainnet * Needs to receive as a second parameter the value `true` to activate the crosschain mode. * Automatically configures an Electrum Bitcoin client to communicate with the Bitcoin mainnet (communication is done through a set of pre-configured Electrum servers) The following code snippet presents the usage of this function: ```typescript import * as ethers from "ethers" import { TBTC } from "@keep-network/tbtc-v2.ts" // Create an Ethers provider. Pass the URL of an Ethereum and Arbitrum mainnet node. // For example, Alchemy or Infura. const ethProvider = new ethers.providers.JsonRpcProvider("...") const arbProvider = new ethers.providers.JsonRpcProvider("...") // Create an Ethers signer. Pass the private key and the above provider. const arbSigner = new ethers.Wallet("...", provider) // If you want to initialize the SDK, it is enough to pass the provider. const sdk = await TBTC.initializeMainnet(ethProvider, true) // Initialize cross-chain functionality for TBTC on Arbitrum await sdk.initializeCrossChain("Arbitrum", arbSigner); // The SDK will be ready to launch read and write in Arbitrum. ``` {% hint style="info" %} The above code snippet presents just one way of creating an Ethers signer/provider. Please refer [Ethers v5 documentation](https://docs.ethers.org/v5/api) to learn more. {% endhint %} ## Testnet The SDK addresses it by exposing the `TBTC.initializeSepolia` function. That function: * Takes
프로젝트로 돌아가기