MultiSigWallet in Libra

I have a question. Is it possible to write or use a MultiSigWallet in Libra or is there no functionality provided yet?
Thanks :slight_smile:

Yes. Libra supports K-of-N multisig accounts/transactions, which you can use to implement a multisig wallet.

Here are some code/doc pointers that should help–let us know if you have more questions!


1 Like

Hey sam, thanks for your answer.
I was wondering if it would be possible to create a multisig wallet by creating/coding a module.
And after that publishing this module under a new created account.
Or is there a better way to create a multisig wallet?

Yes, it is also possible to create a multisig wallet via a module. Something like

module KofNMultisig {
  resource struct Wallet<T> { addrs: vector<address>, threshold: u8, funds: Diem::Coin<T> }
  resource struct Proposal { destination: address, amount: u64, yes_votes: u8, no_votes: u8 }
  public fun publish<T>(account: &signer, threshold) { ... }
  public fun propose<T>(account: &signer, destination: address, amount: u64) { ... }
  public fun vote<T>(account: &signer, vote: bool, multisig_addr: address) { ... }
  public fun execute_proposal(account: &signer, multisig_addr: address) { ... }

would work.

Although both work, there are several advantages to using the built-in multisig transaction feature of Diem instead of a module. For example:

  • Atomicity: either a quorom of signers approves the multisig spend in a single tx, or it cannot be committed at all. In the module case, the signatures on a particular proposal are aggregated over multiple txes.
  • Generality: Diem’s multisig transaction allows an account to require multisig authorization for an arbitrary action (e.g., key rotation, child account creation, minting/burning, …), not just spending.
  • Simplicity: the tx feature already exists and has been extensively tested
1 Like

Thanks Sam,
do you know how i could hard code some owners in the vector address or how I can get die public keys of some created accounts so I can hard code them in the vector?
Thanks a lot

The dev docs on address and vector should help with this:

A code snippet like

fun init(account: &signer) {
  let addresses = Vector::new<address>();
  Vector::push_back(&mut addresses, Signer::address_of(account));
  Vector::push_back(&mut addresses, 0xb0b);

will create a vector containing the signer's address and the hardcoded address 0xb0b.

1 Like

Thank you :slight_smile:
About the function publish you mentioned before, what exactly is the purpose of it?
vote and execute proposal is clear for me :slight_smile:

publish is to create the Wallet<T> resource and publish it under account.