# SDK 入門

## <mark style="color:blue;">安裝</mark>

安裝套件時使用

{% tabs %}
{% tab title="TypeScript" %}

```typescript
npm install @akashicpay/sdk
#or
yarn add @akashicpay/sdk
```

{% endtab %}

{% tab title="PHP" %}

```php
# Pre-Reqs
# Requires at least PHP 7.0 and either the gmp or bcmath extension

composer require akashic/akashic-pay
```

{% endtab %}

{% tab title="Java" %}

```java
# In case of Maven
<dependencies>
    <dependency>
        <groupId>com.akashicpay</groupId>
        <artifactId>AkashicPaySDK</artifactId>
        <version>[version]</version>
    </dependency>
</dependencies>

# In case of Gradle
dependencies {
  implementation 'com.akashicpay:AkashicPaySDK:[version]'
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
$ dotnet add package AkashicPaySDK
```

{% endtab %}

{% tab title="Go" %}

```go
go get github.com/akashicpay/akashicpay-go
```

{% endtab %}
{% endtabs %}

### <mark style="color:blue;">註冊</mark>

創建一個 [AkashicLink](/traditional-chinese/jian-jie/shu-yu.md#akashiclink) 帳號，並在 AkashicPay.com 上完成註冊程序，包括根據需要設置回調 URL，如[快速指南](/traditional-chinese/zhi-nan/kuai-su-zhi-nan.md)中所述。

`l2Address` - 位於 [AkashicLink](/traditional-chinese/jian-jie/shu-yu.md#akashiclink) 的頂部欄位。

`privateKey` - 登入 AkashicPay -> [密鑰對設置](/traditional-chinese/yi-biao-ban/kai-fa-zhe.md#chan-sheng-fu-zhu-mi-yue-dui) -> 使用 [API/SDK 密鑰對](/traditional-chinese/zhi-nan/mi-yue-dui-zhi-nan-with-tk.md#apisdk-mi-yue-dui)

### <mark style="color:blue;">建構</mark>

本範例設定使用許多可選的建立參數，僅供說明之用。

{% tabs %}
{% tab title="TypeScript" %}

```typescript
using AkashicPaySDK;
using AkashicPaySDK.Constants;

namespace ApSdkTests;

public class Example
{
    public static async Task Main(string[] args)
    {
        var environment =
            Environment.GetEnvironmentVariable("environment") == "production" ?
                APEnvironment.Production :
                APEnvironment.Development;

        var otk = ApSdkFactory.CreateOtkFromKeyPair("your_private_key", "your_l2Address");
        var sdk = await ApSdkFactory.CreateSdk(environment, otk);
    }

}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require "vendor/autoload.php";

use Akashic\AkashicPay;
use Akashic\Constants\Environment;
use Akashic\Constants\ACNode;
use Akashic\Constants\ACDevNode;

$akashicPay = new AkashicPay([
    // in development, you will use our testnet and testnet L1 chains
    'environment' => getenv('environment') === 'production' ? Environment::PRODUCTION : Environment::DEVELOPMENT,
    // optional, the SDK will try to find the fastest node if omitted
    'targetNode' => getenv('environment') === 'production' ? ACNode::SINGAPORE_1 : ACDevNode::SINGAPORE_1,
    // use whatever secret management tool you prefer to load the private key
    // from your AkashicLink account. It should be of the form:
    // `"0x2d99270559d7702eadd1c5a483d0a795566dc76c18ad9d426c932de41bfb78b7"`
    // In development, each developer could have their own, or omit this (and
    // the l2Address), in which case the SDK will create and use a new pair.
    // you can instead use your Akashic Link account's 12-word phrase, using the
    // argument `recoveryPhrase`
    'privateKey' => getenv('akashicKey'),
    // this is the address of your AkashicLink account. Of the form "AS1234..."
    'l2Address' => getenv('l2Address'),
]);
```

{% endtab %}

{% tab title="Java" %}

```java
import com.akashicpay.constants.APEnvironment;
import com.akashicpay.model.ACOtk;
import com.akashicpay.sdk.IAPSdk;

public class Main {

    public static void main(String[] args) throws Exception {
        ACOtk otk = APSdkFactory.createOtkFromKeyPair("your_private_key", "your_l2_address");

        APEnvironment environment =
                System.getenv("environment").equals("production") ?
                        APEnvironment.Production : APEnvironment.Development;

        IAPSdk sdk = APSdkFactory.createSDK(environment, otk);
    }
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using AkashicPaySDK;
using AkashicPaySDK.Constants;

namespace ApSdkTests;

public class Example
{
    public static async Task Main(string[] args)
    {
        var environment =
            Environment.GetEnvironmentVariable("environment") == "production" ?
                APEnvironment.Production :
                APEnvironment.Development;

        var otk = ApSdkFactory.CreateOtkFromKeyPair("your_private_key", "your_l2Address");
        var sdk = await ApSdkFactory.CreateSdk(environment, otk);
    }

}
```

{% endtab %}

{% tab title="Go" %}

```go
import (
	"os"

	akashicpay "github.com/akashic/go-sdk"
)

// use whatever secret management tool you prefer to load the private key
// from your AkashicLink account. It should be of the form:
// "0x2d99270559d7702eadd1c5a483d0a795566dc76c18ad9d426c932de41bfb78b7"
apKey := os.Getenv("ApKey")
// this is the address of your AkashicLink account. Of the form "AS1234..."
apL2Address := os.Getenv("ApL2Address")

// in development, you will use our testnet and testnet L1 chains
env := os.Getenv("Environment")
apEnv := akashicpay.Development

if env == "Prod" {
	apEnv = akashicPay.Production
}

// instantiate an SDK instance, ready to use
ap, err := akashicpay.NewAkashicPay(apKey, apL2Address, apEnv, "")
	
```

{% endtab %}
{% endtabs %}

現在您可以使用 AkashicPay 了！要瞭解更多關於不同功能的資訊，請前往下一頁。繼續閱讀以獲得更多關於 AkashicPay 進階設定和測試的詳細資訊。

## <mark style="color:blue;">測試</mark>

您也可以在 [AkashicChain](/traditional-chinese/jian-jie/shu-yu.md#akashicchain) Testnet & Sepolia (Ethereum)，Shasta (Tron)，幣安智能測試鏈 (BNB Smart Chain Testnet) 和索拉拉 (Solana Devnet) 測試網使用 AkashicPay，這對本地開發和測試環境非常有用。要做到這一點，不遵循上述相同的設置，但使用 [AkashicLink](/traditional-chinese/jian-jie/shu-yu.md#akashiclink) 和testnet.akashicpay.com 的測試 (testnet) 版本。SDK 設定幾乎相同，但請注意必須使用 「測試」 環境。

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { AkashicPay, Environment } from "@akashicpay/sdk";

const privateKey = process.env.akashicKey;
const l2Address = process.env.l2Address;

const akashicPay = await AkashicPay.build({
  privateKey,
  l2Address,
  environment: Environment.Development,
});

// Now, e.g. create a wallet on the Tron Shasta testnet
const { address } = await akashicPay.getDepositAddress(
  NetworkSymbol.Tron_Shasta,
  "EndUser123"
);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require "vendor/autoload.php";

use Akashic\AkashicPay;
use Akashic\Constants\Environment;
use Akashic\Constants\NetworkSymbol;

// production is the default environment.
// And in production, an otk must be specified
$akashicPay = new AkashicPay([
    'environment' => Environment::DEVELOPMENT,
    'privateKey' => getenv('akashicKey'),
    'l2Address' => getenv('l2Address'),
]);

// Now, e.g. create a wallet on the Tron Shasta testnet
$address = $akashicPay->getDepositAddress(NetworkSymbol::TRON_SHASTA, 'user123');
```

{% endtab %}

{% tab title="Java" %}

```java
import com.akashicpay.constants.APEnvironment;
import com.akashicpay.model.ACOtk;
import com.akashicpay.model.APDepositAddressResult;
import com.akashicpay.model.APNetworkSymbol;
import com.akashicpay.sdk.IAPSdk;

public class Main {

    public static void main(String[] args) throws Exception {
        String l2Address = "your l2Address";
        String privateKey = "your privateKey";

        ACOtk otk = APSdkFactory.createOtkFromKeyPair(privateKey, l2Address);

        IAPSdk sdk = APSdkFactory.createSDK(APEnvironment.Development, otk);

        APDepositAddressResult trxDepositAddress =
                sdk.getDepositAddress(APNetworkSymbol.TRX_SHASTA, "EndUser123");
    }
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using AkashicPaySDK;
using AkashicPaySDK.Constants;
using AkashicPaySDK.Model;

namespace ApSdkTests;

public class Example
{
    public static async Task Main(string[] args)
    {
        var l2Address = "your l2Address";
        var privateKey = "your privateKey";
        var otk = ApSdkFactory.CreateOtkFromKeyPair(l2Address,privateKey);

        var sdk = await ApSdkFactory.CreateSdk(APEnvironment.Development, otk);

        var trxDepositAddress = await sdk.GetDepositAddressAsync(TronShastaNetworkSymbol.Value, "test005");
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
import (
	"os"

	akashicpay "github.com/akashic/go-sdk"
)

apKey := os.Getenv("ApTestKey")
apL2Address := os.Getenv("ApTestL2Address")

// in development, you will use our testnet and testnet L1 chains
apEnv := akashicpay.Development

// instantiate an SDK instance, ready to use
ap, err := akashicpay.NewAkashicPay(apKey, apL2Address, apEnv, "")

if err != nil {
// handle error
}

// Now, e.g. create a wallet on the Tron Shasta testnet
dA, err := ap.GetDepositAddress(akashicpay.Tron_Shasta, "user123", "")
```

{% endtab %}
{% endtabs %}

## <mark style="color:blue;">回調</mark>

要完成整合，請確保您在指定的組態設定中加入您的[**回調 URL**](/traditional-chinese/yi-biao-ban/kai-fa-zhe.md#hui-diao-url-pei-zhi)。這些 URL 對於在我們的系統之間實現安全通訊、無縫處理驗證或資料交換至關重要。

如需更深入的技術指導，包括所需的 URL 格式、安全性最佳實務和疑難排解，請參閱我們的[回調文件](/traditional-chinese/hui-diao/cun-kuan-hui-diao-deposit-callback.md)。


---

# 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.akashicpay.com/traditional-chinese/sdk/sdk-ru-men.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.
