gnolang / gnonative

Develop for Gno using your app's native language
Apache License 2.0
9 stars 9 forks source link

chore: Add API AddressFromMnemonic #156

Closed jefft0 closed 1 month ago

jefft0 commented 1 month ago

In the API, add the utility function AddressFromMnemonic which creates an in-memory keystore, creates the key from the mnemonic and returns the address. The following example gets the test_1 address from the mnemonic. As expected, it prints address g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5.

    addr, err := client.AddressFromMnemonic(
        context.Background(),
        connect.NewRequest(&api_gen.AddressFromMnemonicRequest{
            Mnemonic: "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast",
        }),
    )
    if err != nil {
        return err
    }

    bech32, err := client.AddressToBech32(
        context.Background(),
        connect.NewRequest(&api_gen.AddressToBech32Request{
            Address: addr.Msg.Address,
        }),
    )
    if err != nil {
        return err
    }

    fmt.Println("address", bech32.Msg.Bech32Address)