Code Monkey home page Code Monkey logo

finschia-kt's Introduction

finschia-kt

gRPC client library in kotlin for finschia (https://github.com/Finschia/finschia).

Requires finschia-sdk v0.47.0-alpha1

Current finschia-sdk version applied to finschia-kt/protobuf is finschia-sdk v0.47.0-alpha1

Build

You can build the project by following command, which also runs all the unit tests:

$ git submodule update --init
$ ./gradlew build

Note that any version of finschia-kt is only compatible with a certain finschia-sdk version. The corresponding finschia-sdk version that the current repository supports can be found in the tag or commit hash of proto/repositories/finschia-sdk submodule, using the following command.

$ cd protobuf/repositories/finschia-sdk && git describe --always && cd -

If you are a finschia-kt developer or contributor and trying to use another version of finschia-sdk, git checkout the appropriate version in the finschia-sdk submodule before building this repository. The following command is an example of using finschia-sdk v0.47.0-alpha1.

$ cd protobuf/repositories/finschia-sdk && git checkout v0.47.0-alpha1 && cd -

How to use

1. How to get a Bech32 address from the KeyWallet

You can get the address by:

val alicePubKey: PubKey = ...
val aliceAddress = Address(alicePubKey).toBech32(accountPrefix)

2. How to validate a Bech32 address

You can check the address by:

val testingAddress: String = "link..."
val tested = Address(testingAddress) // this will throw if the address is invalid

3. How to create raw transaction for LN transfer

val unsignedBytes = ConcreteScenarios.createBankMsgSendSingleDirect(
    aliceAddress, // sender address
    bobAddress,   // recipient address
    10000,        // amount in base denom
    alicePubKey,  // sender public key
    1,            // sender sequence
    100000,       // timeout height
    "",           // memo
)

4. How to create a signature

val signedBytes = ConcreteScenarios.signSingleDirect(
    unsignedBytes, // unsigned tx bytes
    aliceWallet,   // signer wallet
    0,             // signer account number
)

Examples

We provide simple client programs.

with-tx-wrapper-example and without-tx-wrapper-example show how to create tx and send it. The former is using the tx wrapper, while the latter does not use the wrapper.

multisig-example shows how to create multisig tx and send it.

query-example shows how to query account information.

How to run without-tx-wrapper-example

1. Run finschia-sdk simapp

Build with reference to Quick Start build.

Initialize and configure simapp.

$ export TEST_MNEMONIC="mind flame tobacco sense move hammer drift crime ring globe art gaze cinnamon helmet cruise special produce notable negative wait path scrap recall have"
$ simd init validator --home ~/simapp --chain-id sim
$ simd keys add alice --keyring-backend=test --home ~/simapp --recover --account=0 <<< ${TEST_MNEMONIC}
$ simd keys add bob --keyring-backend=test --home ~/simapp --recover --account=1 <<< ${TEST_MNEMONIC}
$ simd add-genesis-account $(simd --home ~/simapp keys show alice -a --keyring-backend=test) 100000000000stake,100000000000tcony --home ~/simapp
$ simd add-genesis-account $(simd --home ~/simapp keys show bob -a --keyring-backend=test) 100000000000stake,100000000000tcony --home ~/simapp
$ simd gentx alice 10000000000stake --keyring-backend=test --home ~/simapp --chain-id=sim
$ simd collect-gentxs --home ~/simapp

Run simapp.

$ simd start --home ~/simapp

2. Replace hard-coded arguments

To confirm it's possible to send transactions to the chain created above using finschia-kt, replace the following three parts of the without-tx-wrapper-example/src/main/kotlin/network/link/sdk/example/Client.kt.

  1. Chain ID: constant of the name CHAIN_ID in ConcreteScenarios
    private const val CHAIN_ID = "sim"
    private const val BASE_DENOM = "tcony"
    with the following output:
    $ cat ~/simapp/config/genesis.json | jq '.chain_id'
  2. Account sequences: 5th argument of ConcreteScenarios.createBankMsgSendSingleDirect()
    val unsignedBytes = ConcreteScenarios.createBankMsgSendSingleDirect(
        aliceAddress, // sender address
        bobAddress,   // recipient address
        10000,        // amount in base denom
        alicePubKey,  // sender public key
        1,            // sender sequence
        100000,       // timeout height
        "",           // memo
    )
    with the following outputs, respectively:
    $ simd q account link146asaycmtydq45kxc8evntqfgepagygelel00h | grep sequence
    $ simd q account link1twsfmuj28ndph54k4nw8crwu8h9c8mh3rtx705 | grep sequence
  3. Account number: 3rd argument of ConcreteScenarios.signSingleDirect
    val signedBytes = ConcreteScenarios.signSingleDirect(
        unsignedBytes, // unsigned tx bytes
        aliceWallet,   // signer wallet
        0,             // signer account number
    )
    with the following outputs, respectively:
    $ simd q account link146asaycmtydq45kxc8evntqfgepagygelel00h | grep account_number
    $ simd q account link1twsfmuj28ndph54k4nw8crwu8h9c8mh3rtx705 | grep account_number

3. Run java client

Broadcast transaction and prints the hash of transaction.

$ ./gradlew build
$ ./gradlew :examples:without-tx-wrapper-example:run

Query transaction.

$ simd q tx ${TX_HASH}

finschia-kt's People

Contributors

jaeseung-bae avatar 0tech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.