eosjs icon indicating copy to clipboard operation
eosjs copied to clipboard

eosjs - unable to set the contract using front end method call

Open amolmaid opened this issue 8 years ago • 6 comments

Hi,

I am working on a dAPP whose front end is in reactJS and currently getting the .abi and .wasm files from backend nodeJS via an API response; and trying to set the contract on user's account by taking permission/signature from scatter at front end.

1. Please find my code snippet bellow, publish contract code

2. After accepting the scatter permission I am getting this error, ( I am using binaryen too) binerian error

3. Nodeos showing following error, nodeos error set contract

Note -

I tried the same thing by providing the keys with binaryen also, but it flags the same error msg.

amolmaid avatar Aug 10 '18 12:08 amolmaid

the log says:

authroization = 
Object
  data: [numbers]
  type: Buffer

So that looks like a typo..

The option is called {binaryen} not {binaryen1}.. That is needed and used only if the very beginning of your smart contract data starts with (module ..

Although setcode works with a buffer, I do wonder if HEX might help. You can try with result.data.wasm.data.toString('hex') ..

Lets see more details just about the wasm data your sending, that is what the error is about.

Also, you can try creating Eos with Eos({forceActionDataHex: false, ..}) so you can more easily see what is getting submitted.

jcalfee avatar Aug 10 '18 19:08 jcalfee

Hi @jcalfee ,

Thanks for your response,

I did correct the typo, and tried again; And now tried to see if there is any difference in file's content type.
when I read the file in back end and send it in json, its basically converts the buffer type file to JSON.stringify(wasm) format. So It was still failing to convert it back to the buffered format which we need to pass to eosScatter.setCode() method. Also the JSON.parse(wasm) don't work on received data in front end.

Please check the following results' screen shots 1. Front end code 2 front endfrom 2018-08-13 16-01-15

2. Front end failing browserm 2018-08-13 16-00-27

3. Back end code and output 3 backend rom 2018-08-13 16-04-44

I would be really appreciate if you could guide for this ... Thanks in advance.

amolmaid avatar Aug 13 '18 10:08 amolmaid

Hi,

I was able to solve that one with following line of code eosScatter.setcode(account.name, 0, 0, Buffer.from(JSON.parse(JSON.stringify(result.data.wasm)).data), options2).then((res1, error1) =>{ ...... } -- Not sure how did it work though, but it is actually changing the code of an account correctly, checked via cleos.

Thanks.

amolmaid avatar Aug 14 '18 08:08 amolmaid

Hi, I still stuck at setAbi(), does it has overridden method which takes version as parameter or anything ? I am using this function here eosScatter.setabi(account.name, Buffer.from(result.data.abi.data), options3).then((res, error) => {

abi from 2018-08-14 13-55-01

Please guide for the above error

amolmaid avatar Aug 14 '18 08:08 amolmaid

Version is the 1st field it tries to parse in the ABI. Try [email protected], it accepts more object types for the ABI including Buffer (as seen in the error message).

jcalfee avatar Aug 15 '18 01:08 jcalfee

I am able to solve these both the problems using following code snippet. eosScatter.setcode(account.name, 0, 0, Buffer.from(result.data.wasm.data), options2).then((res1, error1) => { ............ }

and

eosScatter.setabi(account.name, JSON.parse(Buffer.from(result.data.abi.data)), options2).then((res, error) => { ................ }

Note : Make sure you send your WHOLE response from back end in the form of string

Thanks.

amolmaid avatar Aug 27 '18 11:08 amolmaid