<p>There are a few problems, you are passing mnemonic_secret incorrectly resulting in the API call getting a NULL pointer hence returning WALLY_EINVAL. Here is a corrected version, although note that your myArray is still the wrong size:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;wally_bip39.h&gt;

int main()
{
    /* Note that this array is 34 elements long which seems incorrect, it should be 32 */
    const unsigned char myArray[] = { 0x00, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22,  0x33 };
    char *mnemonic_secret;

    int ret = bip39_mnemonic_from_bytes(0, myArray, 32, &amp;mnemonic_secret);
    if (ret != WALLY_OK) {
        printf("mnemonic did not work. error: %d",ret);
        return 1;
    }
    printf("HSM: your should remember / write down the following words do recover your funds!\n");
    printf("%s", mnemonic_secret);
    wally_free_string(mnemonic_secret);
    return 0;
}
</code></pre>

<p>You may get a faster response with wally question by asking on their github at <a href="https://github.com/elementsproject/libwally-core" rel="nofollow noreferrer">https://github.com/elementsproject/libwally-core</a>.</p>

CC BY-SA 4.0
2018-08-12T13:11:37.993Z
yes the array is also to long but it doesn't matter the problem was about passing char ** pointer. In the setting where I am I don't create myArray myself but have it already under control.
Rene Pickhardt
CC BY-SA 4.0
2018-08-10T04:06:42.073Z
2018-08-10T04:06:42.073Z
makriath
<p>what am I doing wrong? it always returns with error -2... I included libwallycore to my project and my IDE tells me it it is available after I also did <code>include &lt;wally_bib39.h&gt;</code></p>

<p>I tried mainting a wordlist myself but then I run into even more mistakes so I guess I am missusing the API. Ca anyone help out pls?</p>

<pre><code>static void display_mnemonic_word_list(void){
    char **mnemonic_secret=NULL;
    //wordlist_init(bip39_wordlist)
    const unsigned char myArray[] = { 0x00, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22,  0x33 };
    int ret = bip39_mnemonic_from_bytes(NULL,myArray,32,mnemonic_secret);
    if (ret!=WALLY_OK){
        printf("mnemonic did not work. error: %d",ret);
    }
    printf("HSM: your should remember / write down the following words do recover your funds!");
    if (mnemonic_secret){
        int i = 0;
        while ( *mnemonic_secret )
            printf( "%d. %s", ++i, *mnemonic_secret++ );
    }
}
</code></pre>

<mnemonic-seed><library><c>
call to bip39_mnemonic_from_bytes in libwally-core returns NULL
Rene Pickhardt
# call to bip39_mnemonic_from_bytes in libwally-core returns NULL

(Asked by: username_0 on 2018-07-27)

what am I doing wrong? it always returns with error -2... I included libwallycore to my project and my IDE tells me it it is available after I also did include 
I tried mainting a wordlist myself but then I run into even more mistakes so I guess I am missusing the API. Ca anyone help out pls?
static void display_mnemonic_word_list(void){
    char **mnemonic_secret=NULL;
    //wordlist_init(bip39_wordlist)
    const unsigned char myArray[] = { 0x00, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22,  0x33 };
    int ret = bip39_mnemonic_from_bytes(NULL,myArray,32,mnemonic_secret);
    if (ret!=WALLY_OK){
        printf("mnemonic did not work. error: %d",ret);
    }
    printf("HSM: your should remember / write down the following words do recover your funds!");
    if (mnemonic_secret){
        int i = 0;
        while ( *mnemonic_secret )
            printf( "%d. %s", ++i, *mnemonic_secret++ );
    }
}

**Tags:** mnemonic-seed, library, c


---

## 1 answers

### Answer by username_1 on 2018-08-10. Score: 2 | Accepted answer

There are a few problems, you are passing mnemonic_secret incorrectly resulting in the API call getting a NULL pointer hence returning WALLY_EINVAL. Here is a corrected version, although note that your myArray is still the wrong size:
#include 
#include 

int main()
{
    /* Note that this array is 34 elements long which seems incorrect, it should be 32 */
    const unsigned char myArray[] = { 0x00, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22, 0x11, 0x22,  0x33 };
    char *mnemonic_secret;

    int ret = bip39_mnemonic_from_bytes(0, myArray, 32, &mnemonic_secret);
    if (ret != WALLY_OK) {
        printf("mnemonic did not work. error: %d",ret);
        return 1;
    }
    printf("HSM: your should remember / write down the following words do recover your funds!\n");
    printf("%s", mnemonic_secret);
    wally_free_string(mnemonic_secret);
    return 0;
}

You may get a faster response with wally question by asking on their github at https://github.com/elementsproject/libwally-core.

> **Comments:**
> **username_0**: yes the array is also to long but it doesn't matter the problem was about passing char ** pointer. In the setting where I am I don't create myArray myself but have it already under control.  

---

