Wallet API Reference

This is reference implementation as wallet APIs. Users are able to implement wallet application based on Client APIs.

Setting

struct iota_wallet_t

IOTA wallet setting.

Public Members

byte_t seed[64]

the mnemonic seed of this wallet

char bech32HRP[8]

The Bech32 HRP of the network. iota for mainnet, atoi for testnet.

uint32_t account_index

wallet account index

iota_client_conf_t endpoint

IOTA node endpoint.

int wallet_update_bech32HRP(iota_wallet_t *w)

Update bech32HRP from network.

Parameters
  • w[in] A wallet instance

Returns

int 0 on success

Create

iota_wallet_t *wallet_create(char const ms[], char const pwd[], uint32_t account_index)

Create a wallet instance from the given mnemonic, password, and account index.

Parameters
  • ms[in] A string of mnemonic, NULL for genrating a random mnemonic

  • pwd[in] A passphase for seed deivation

  • account_index[in] The account index

Returns

iota_wallet_t*

void wallet_destroy(iota_wallet_t *w)

Destory the wallet account.

Parameters
  • w[in] A wallet instance

Endpoint

int wallet_set_endpoint(iota_wallet_t *w, char const host[], uint16_t port, bool use_tls)

Set a node endpoint, if not calling this method default is “http://localhost:14265/”.

Parameters
  • w[in] A wallet instance

  • host[in] The hostname of the node

  • port[in] The port number of the node

  • use_tls[in] if use TLS or not

Returns

int 0 on success

Address

int wallet_address_from_index(iota_wallet_t *w, bool change, uint32_t index, byte_t addr[])

Get an ed25519 address from the given account, change, and index.

https://chrysalis.docs.iota.org/guides/dev_guide/#addresskey-space

Parameters
  • w[in] A wallet instance

  • change[in] The change index which is {0, 1}, also known as wallet chain.

  • index[in] Address index

  • addr[out] A buffer holds ed25519 address

Returns

int 0 on success

int wallet_bech32_from_index(iota_wallet_t *w, bool change, uint32_t index, char addr[])

Get bech32 address from the given account, change, and index.

Parameters
  • w[in] A wallet instance

  • change[in] The change index which is {0, 1}, also known as wallet chain.

  • index[in] Address index

  • addr[out] A buffer holds bech32 address

Returns

int 0 on success

Balance

int wallet_balance_by_address(iota_wallet_t *w, byte_t const addr[], uint64_t *balance)

Get balance by a given address.

Parameters
  • w[in] A wallet instance

  • addr[in] An address for query

  • balance[out] The balance of the address

Returns

int 0 on success

int wallet_balance_by_bech32(iota_wallet_t *w, char const bech32[], uint64_t *balance)

Get balance from a given bech32 address.

Parameters
  • w[in] A wallet instance

  • bech32[in] A string of bech32 address

  • balance[in] The balance of the address

Returns

int 0 on success

int wallet_balance_by_index(iota_wallet_t *w, bool change, uint32_t index, uint64_t *balance)

Get address balance by a given index.

Parameters
  • w[in] A wallet instance

  • change[in] Is change address

  • index[in] The index of address

  • balance[out] The balance of the address

Returns

int 0 on success

Send

int wallet_send(iota_wallet_t *w, bool change, uint32_t addr_index, byte_t receiver[], uint64_t balance, char const index[], byte_t data[], size_t data_len, char msg_id[], size_t msg_id_len)

Send message to the Tangle.

Parameters
  • w[in] A wallet instance

  • change[in] Is change/chain address?

  • sender_index[in] The address index of this wallet

  • receiver[in] The receiver address in ed25519 format

  • balance[in] The balance to send

  • index[in] An optional indexation

  • data[in] An optional indexation data, it’s ignored if the index parameter is NULL

  • msg_id[out] A buffer holds the message ID string that returned from the node.

  • msg_id_len[in] The length of msg_id buffer.

Returns

int 0 on success

Mnemonic Sentence

enum ms_lan_t

Mnemonic supported languages with ISO 639-1 suffixes.

Values:

enumerator MS_LAN_EN

English.

enumerator MS_LAN_KO

Korean.

enumerator MS_LAN_ES

Spanish.

enumerator MS_LAN_ZH_HANT

Chinese Traditional.

enumerator MS_LAN_ZH_HANS

Chinese Simplified.

enumerator MS_LAN_FR

French.

enumerator MS_LAN_IT

Italian.

enumerator MS_LAN_CS

Czech.

enumerator MS_LAN_PT

Portuguese.

enum ms_entropy_t

Init entropy of mnemonic sentense.

With more entropy security is improved but the sentence length increases.

Values:

enumerator MS_ENTROPY_128

12 mnemonic words

enumerator MS_ENTROPY_160

15 mnemonic words

enumerator MS_ENTROPY_192

18 mnemonic words

enumerator MS_ENTROPY_224

21 mnemonic words

enumerator MS_ENTROPY_256

24 mnemonic words

int mnemonic_to_seed(char const ms[], char const pwd[], byte_t seed[], size_t seed_len)

Drive seed from a given mnemonic sentence.

Parameters
  • ms[in] A mnemonic sentence

  • pwd[in] A password string

  • seed[out] A buffer holds output seed

  • seed_len[in] the length of seed buffer

Returns

int

int mnemonic_generator(ms_entropy_t ent_len, ms_lan_t lang, char ms[], size_t ms_len)

Generate a randome word list from given entropy length.

Parameters
  • ent_len[in] the init entropy length

  • lang[in] the language of mnemonic

  • ms[out] a buffer holds the mnemonic string

  • ms_len[in] the length of mnemonic buffer

Returns

int 0 on success

int mnemonic_encode(byte_t const entropy[], ms_entropy_t ent_len, ms_lan_t lan, char ms_out[], size_t ms_len)

encode mnemonic sentence from a given entropy.

Parameters
  • entropy[in] the input entroty

  • ent_len[in] the length of entroty, should be one of 16, 20, 24, 28, 32.

  • lan[in] The expected language of mnemonic sentence

  • ms_out[out] The output string of mnemonic sentence

  • ms_len[in] the output buffer length

Returns

int 0 on success

size_t mnemonic_decode(char const ms_strs[], ms_lan_t lan, byte_t entropy[], size_t ent_len)

decode mnemonic sentence to the entropy.

Parameters
  • ms_strs[in] A string of mnemonic sentence

  • lan[in] The language of the mnemonic sentence

  • entropy[out] the output buffer, should bigger than 33 bytes(ENT+CS)

  • ent_len[in] the size of the entropy buffer

Returns

size_t the bytes written to output buffer, 0 on failed.

int mnemonic_convertor(char const from[], ms_lan_t lan_from, char to[], size_t to_len, ms_lan_t lan_to)

Convert mnemonic to another language.

Parameters
  • from[in] A source mnemonic sentence

  • lan_from[in] The language of source mnemonic

  • lan_to[in] The language of target mnemonic

  • to[out] A buffer for target mnemonic

  • to_len[out] The length of target buffer

Returns

int

bool mnemonic_validation(char const ms[], ms_lan_t language)

Check if mnemonic sentence is valid.

Parameters
  • ms[in] A string of mnemonic sentence

  • language[in] The language of the given mnemonic

Returns

true valid sentence

Returns

false invalid sentence