eosjs icon indicating copy to clipboard operation
eosjs copied to clipboard

How to use `eosjs` with multiple dynamic keys provider

Open navcsdev opened this issue 8 years ago • 8 comments

My case, when an account call my action in my contract they will provide keyProvider then I must re-create eosjs with new keyProvider.

Do we have another way to solve it ? 🙇

navcsdev avatar Aug 01 '18 17:08 navcsdev

Pass a function: keyProvider = () => dynamicKeys

jcalfee avatar Aug 01 '18 21:08 jcalfee

@jcalfee same problem for me, would you please tell how to do that? or is there an example available? thanks so much!

ghost avatar Aug 17 '18 03:08 ghost

See configuration keyProvider..

If a function is provided, this function is called for each transaction.

let userProvidedKey = null
eos = Eos({keyProvider: ()=> userProviderKey})

// set the key
userProvidedKey=privateKey1
await eos.someAction('user' ..)

// change the key
userProvidedKey=privateKey2
await eos.someAction('user2' ..)

I could add a feature and accept the keyProvider here too:

// proposed, does not work
await eos.someAction('user2' .., {keyProvider: privateKey2})

The proposed change does not leave the variable userProvidedKey layout around..

jcalfee avatar Aug 18 '18 15:08 jcalfee

@jcalfee great job, I'am so appreciate that and will follow this guide. thank you very much!

ghost avatar Aug 19 '18 12:08 ghost

@jcalfee so appreciate! but maybe there is a spell mistake in 'userProviderKey/userProvidedKey'

co1ingue avatar Aug 23 '18 08:08 co1ingue

Where is the spelling mistake?

jcalfee avatar Aug 23 '18 22:08 jcalfee

Pass a function: keyProvider = () => dynamicKeys

How can I do it in eosjs@beta ?

IhorPeresunko avatar Oct 29 '18 16:10 IhorPeresunko

Scatter use new Proxy class for inject custom keyprovider.

Also you can use iteratible object with multiple keys for JsSignatureProvider

iKest avatar Oct 29 '18 16:10 iKest