bpancost / sila

An SDK for Sila written in Golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sila Client

This project creates a native SDK for the Sila API in Golang. To learn more about Sila and how it works, please go to their website as well as read the documentation.

Implemented Endpoints

The current version of this library implements the following endpoints according to the Sila API v0.2.

Entities

Accounts

Wallets

Transactions

Parameters

Usage

To use the Sila SDK, first import:

import "github.com/bpancost/sila"

From there, create a new client by using

// The the auth private key as a hex string, without the "0x" prefixed
privateKeyHex := "badba7368134dcd61c60f9b56979c09196d03f5891a20c1557b1afac0202a97c"
// The handle associated with your auth account
authHandle := "handle.silamoney.eth"
// A production client can be created by using sila.Production instead of sila.Sandbox
client, err := sila.NewClient(privateKeyHex, authHandle, sila.Sandbox)

With the client, it is possible to make any of the included calls. Each is a chainable series of method calls, ending with a call to the Do method. For example, to get a list of entities you could use

response, err := silaClient.GetEntities().
                            SetPage(1).
                            SetPerPage(20).
                            Do()

There are several functions within the github.com/bpancost/sila package which can be used to manipulate or create keys for wallets, which will be required for certain calls.

  • GenerateNewPrivateKey() (string, error)
    • Generates a private key for a new wallet. This should generally not be shared or shown outside of your system and will be used for subsequent calls related to the wallet, or as a means of identifying the user who owns the wallet.
  • GetWalletAddress(privateKeyHex string) (string, error)
    • Gets the public address for the wallet. This is used to publicly indicate a wallet and is always visible on the blockchain, including any transactions.
  • GenerateWalletSignature(message []byte, walletPrivateKeyHex string) (string, error)
    • Signs an arbitrary message using a wallet's private key as a hex string.

Integration Tests

To use the included integration tests, create a file named test_config.yaml using the test_config_sample.yaml as a template. Provide your auth key as a hex string, your auth handle, a unique user handle specifically for this testing, and a private key as a hex string for the integration user's wallet which will be their main wallet. You can use a tool like Vanity-Eth to help generate a new wallet address and private key.

Most tests will complete quickly, though the transaction tests require several minute sleeps to verify they completed and will take around 10 minutes to complete.

If you would like to view the integration test progress via a web page, you can use goconvey from a terminal and then navigate to http://127.0.0.1:8080.

About

An SDK for Sila written in Golang.

License:MIT License


Languages

Language:Go 100.0%