1

The smart contract takes a string as an input for the public key. I need to convert it into a public key object within the contract.

1 Answer 1

1

You would do it as follows:

eosio::public_key string_to_public_key(unsigned int const key_type, std::string const & public_key_str)
{
  eosio::public_key public_key;
  public_key.type = key_type; // Could be K1 or R1 enum
  for(int i = 0; i < 33; ++i)
  {
    public_key.data.at(i) = public_key_str.at(i);
  }
  return public_key;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.