Full Documentation

This lists the full functionality available in the PHP SDK.

Prerequisites: Version 0.2 requires PHP 7.2 or later.

PHP Extensions Required: - ext-curl - ext-json - ext-mbstring - ext-gmp (not usually enabled by default)

Usage

Add the SDK from the Packagist to your project. The SDK is available here.

Via Composer:

composer require silamoney/php-sdk:0.2.2

Initialize the application

require_once 'vendor/autoload.php';
use Silamoney\Client\Api\SilaApi;
use Silamoney\Client\Domain\{BalanceEnvironments,Environments};
// Load your credentials
$appHandle = 'your app handle';
$privateKey = 'your private key';
// Create your client
$client = new SilaApi('your sila endpoint url', 'your sila balance endpoint url', $appHandle, $privateKey); // From custom URL
$client = SilaApi::fromEnvironment(Environments::SANDBOX, BalanceEnvironments::SANDBOX, $appHandle, $privateKey); // From predefined environments
$client = SilaApi::fromDefault($appHandle, $privateKey); // From default sandbox environments

This sets up the app private key and handle for the SDK to use for signing subsequent requests. The other SDK functionality will not be available until this configuration is completed. The SDK does not store this information outside of the instance that is configured. Private keys are never transmitted over the network or stored outside the scope of this instance.

You can manage your apps in the Developer Console. The privateKey is the Private Key that matches the Public Key associated with the Application Handle in your Console.

Keep your Application Private Key secure! Never share it with anyone, including us. If you believe that your private key has been compromised, please replace the key for that app with a new one in the Developer Console.

User Methods

Check Handle

Checks the availability of userHandle so that it can be used in user registration.

$userHandle = 'user.silamoney.eth';
$response = $client->checkHandle($userHandle); // Returns Silamoney\Client\Api\ApiResponse

Success Response Object 200 OK

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // User is available

Failure Response Object 200 OK

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // FAILURE
echo $response->getData()->getMessage(); // User is already taken

Generate Wallet

This is a helper function that allows you to generate a wallet (private key & address) that you can then use to register a new user.

Important! Sila does not custody these private keys. They should never be sent to us or disclosed to any third party. The private key will be used to sign all requests from the associated user for authentication purposes.

$wallet = $client->generateWallet();
print $wallet->getAddress(); // e.g. 0x9ae1e2a685c5f23981757ea0cb6f5b413aa5f29f
print $wallet->getPrivateKey(); // e.g. 0xe62049e7ca71d9223c8db6751e007ce000d686b7729792160787034e1c976c12

You can also initialize a wallet using existing values, e.g.

$privateKey = '0xe62049e7ca71d9223c8db6751e007ce000d686b7729792160787034e1c976c12';
$address = '0x9ae1e2a685c5f23981757ea0cb6f5b413aa5f29f';
$wallet = $client->generateWallet($privateKey, $address);
print $wallet->getAddress(); // e.g. 0x9ae1e2a685c5f23981757ea0cb6f5b413aa5f29f
print $wallet->getPrivateKey(); // e.g. 0xe62049e7ca71d9223c8db6751e007ce000d686b7729792160787034e1c976c12

Wallet has two attributes:

  • address is the public blockchain address that will be used when you call register()

  • private_key is the private key associated with this address. This will only be used to sign requests. Keep this safe!

Register

Attaches KYC data and specified blockchain address to an assigned handle.

use Silamoney\Client\Domain\User;
// Fill your data
$userHandle = 'user.silamoney.eth';
$firstName = 'Sila';
$lastName = 'Money';
$streetAddress1 = 'Some location';
$streetAddress2 = 'In the world';
$city = 'your beautiful city';
$state = 'NY'; // 2 characters code only
$postalCode = '12345'; // can be 5 or 9 digits format
$phone = '1234567';
$email = 'you@awesomedomain.com';
$cryptoAdress = '0xabc123abc123abc123'; // Hex-encoded blockchain address (prefixed with "0x")
$identityNumber = 'AAA-GG-SSSS'; // SSN format
$birthDate = new DateTime::createFromFormat('m/d/Y', '1/8/1935'); // Only date part will be taken when sent to api
// Create user object
$user = new User($userHandle, $firstName, $lastName, $streetAddress1, $streetAddress2,
$city, $state, $postalCode, $phone, $email, $cryptoAdress, $identityNumber, $birthDate);
// Call the api
$response = $client->register($user);

Success Response Object

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // User was successfully register

RequestKYC

Starts KYC verification process on a registered user handle.

$userHandle = 'user.silamoney.eth';
$userPrivateKey = 'some private key'; // Hex format
$response = $client->requestKYC($userHandle, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // User submitted for KYC review.

CheckKYC

Returns whether the entity attached to the user handle is verified, not valid, or still pending.

$userHandle = 'user.silamoney.eth';
$userPrivateKey = 'some private key'; // Hex format
$response = $client->checkKYC($userHandle, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // User has passed ID verification!

LinkAccount

Uses a provided Plaid public token to link a bank account to a verified entity. More detail & Plaid public key is available here.

// Load your information
$userHandle = 'user.silamoney.eth';
$accountName = 'Custom Account Name';
$publicToken = 'public-xxx-xxx';
$userPrivateKey = 'some private key'; // Hex format
// Call the api
$response = $client->linkAccount($userHandle, $accountName, $publicToken, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(); // 200
echo $response->getData()->getStatus(); // SUCCESS

GetAccounts

Gets basic bank account names linked to user handle.

$userHandle = 'user.silamoney.eth';
$userPrivateKey = 'some private key'; // Hex format
$response = $client->getAccounts($userHandle, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(); // 200
$accounts = $response->getData(); // Array of Silamoney\Client\Domain\Account
echo $accounts[0]->accountName; // Account Name
echo $accounts[0]->accountNumber; // Account Number
echo $accounts[0]->accountStatus; // Account Status
echo $accounts[0]->accountType; // Account Type

IssueSila

Debits a specified account and issues tokens to the address belonging to the requested handle.

// Load your information
$userHandle = 'user.silamoney.eth';
$amount = 1000;
$accountName = 'Custom Account Name';
$userPrivateKey = 'some private key'; // Hex format
// Call the api
$response = $client->issueSila($userHandle, $amount, $accountName, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // Transaction submitted to processing queue.

TransferSila

Starts a transfer of the requested amount of SILA to the requested destination handle.

// Load your information
$userHandle = 'user.silamoney.eth';
$destination = 'user2.silamoney.eth';
$amount = 1000;
$userPrivateKey = 'some private key'; // Hex format
// Call the api
$response = $client->transferSila($userHandle, $destination, $amount, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(): // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // Transaction submitted to processing queue.

RedeemSila

Burns given the amount of SILA at the handle's blockchain address and credits their named bank account in the equivalent monetary amount.

// Load your information
$userHandle = 'user.silamoney.eth';
$amount = 1000;
$accountName = 'Custom Account Name';
$userPrivateKey = 'some private key'; // Hex format
// Call the api
$response = $client->redeemSila($userHandle, $amount, $accountName, $userPrivateKey);

Success Response Object

use Silamoney\Client\Domain\SearchFilters;
// Load your information
$userHandle = 'user.silamoney.eth';
$filters = new SearchFilters(); // <https://docs.silamoney.com/?plaintext#search_filters>
$userPrivateKey = 'some private key'; // Hex format
// Call the api
$response = $client->getTransactions($userHandle, $filters, $userPrivateKey);

GetTransactions

Gets transactions for a specific blockchain address & handle.

use Silamoney\Client\Domain\SearchFilters;
// Load your information
$userHandle = 'user.silamoney.eth';
$filters = new SearchFilters(); // <https://docs.silamoney.com/?plaintext#search_filters>
$userPrivateKey = 'some private key'; // Hex format
// Call the api
$response = $client->getTransactions($userHandle, $filters, $userPrivateKey);

Success Response Object

echo $response->getStatusCode(); // 200
$results = $response->getData(); // Silamoney\Client\Domain\GetTransactionsResponse

SilaBalance

Gets Sila balance for a given blockchain address.

$address = '0xabc123abc123abc123'
$response = $client->silaBalance($address);

Success Response Object

echo $response->getStatusCode(); // 200
$results = $response->getData(); // 1000 (amount of sila tokens)

Plaid Sameday Auth

Gets a public token to complete the second phase of Plaid's Sameday Microdeposit authorization.

$userHandle = 'user.silamoney.eth';
$accountName = 'Custom Account Name';
$response = $client->plaidSamedayAuth($userHandle, $accountName);

Success Response Object

echo $response->getStatusCode(); // 200
echo $response->getData()->getReference(); // Random reference number
echo $response->getData()->getStatus(); // SUCCESS
echo $response->getData()->getMessage(); // Plaid public token succesfully created
echo $response->getData()->getPublicToken(); // Token