# Getting Started with SDK

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

Install the package with

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

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

{% endtab %}

{% tab title="PHP" %}

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

composer require akashic/akashic-pay
```

{% endtab %}

{% tab title="Java" %}

```bash
# 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#" %}

```bash
$ dotnet add package AkashicPaySDK
```

{% endtab %}

{% tab title="Go" %}

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

{% endtab %}
{% endtabs %}

### <mark style="color:blue;">**Register**</mark>

Create an [AkashicLink](https://docs.akashicpay.com/introduction/terminology#akashiclink) account and go through the registration process on [AkashicPay.com](https://docs.akashicpay.com/introduction/terminology#akashicpay.com) including setting up callback URLs as desired, as described in the [Quick Guide](https://docs.akashicpay.com/guides/quick-guide).

`l2Address` - Located at the top bar of [AkashicLink](https://docs.akashicpay.com/introduction/terminology#akashiclink)

`privateKey` - Login AkashicPay -> [KeyPair Settings](https://docs.akashicpay.com/dashboard/developers#generate-secondary-keypair) -> Use the [API/SDK KeyPair](https://docs.akashicpay.com/guides/keypairs-guide#api-sdk-keypair)

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

This example configuration uses many optional build arguments, for illustration purposes.

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

```javascript
import type { IHttpClient, ILogger } from "@akashicpay/sdk";
import { ACDevNode, ACNode, AkashicPay, Environment } from "@akashicpay/sdk";
import axios from "axios";
import pino from "pino";
import { Environment } from "@akashicpay/sdk/src";

// 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
// `build()` argument `recoveryPhrase`
const privateKey = process.env.akashicKey;
// this is the address of your AkashicLink account. Of the form "AS1234..."
const l2Address = process.env.l2Address;
// in development, you will use our testnet and testnet L1 chains
const environment =
  process.env.environment == "production"
    ? Environment.Production
    : Environment.Development;
// you're strongly encouraged to pass an instance of your preferred logger
const logger: ILogger = pino({ name: "AkashicPaySDK" });
// optional, the SDK will try to find the fastest node if omitted
const targetNode =
  environment == "development" ? ACNode.SingaporeDAI : ACDevNode.Singapore1;

// instantiate an SDK instance, ready to use
const akashicPay = await AkashicPay.build({
  privateKey,
  l2Address,
  environment,
  targetNode,
  logger,
});
```

{% 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 %}

You are now ready to use AkashicPay! To learn more about the different functions, go to the next page. Continue reading for more details about advanced setup of AkashicPay and testing.

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

You can also use AkashicPay with the [AkashicChain](https://docs.akashicpay.com/introduction/terminology#akashicchain) Testnet & **Sepolia** (Ethereum), **Shasta** (Tron), **BNB Smart Chain Testnet** and **Solana (Devnet)** testnets, useful for local development and staging environments. To do this, follow the same setup as above, but use testnet versions of AkashicLink and testnet.akashicpay.com. The SDK setup is almost identical, though note that the "Development" environment must be used.

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

```javascript
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" %}
{% code overflow="wrap" %}

```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');

```

{% endcode %}
{% 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;">Callbacks</mark>

To complete the integration, please ensure you add your [**Callback URLs**](https://docs.akashicpay.com/dashboard/developers#callback-settings) in the designated configuration settings. These URLs are essential for enabling secure communication between our systems and handling authentication or data exchange seamlessly.

For more in-depth technical guidance—including required URL formats, security best practices, and troubleshooting—please refer to our [Callback Documentation](https://docs.akashicpay.com/callbacks).
