eosjs - unable to set the contract using front end method call
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,

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

3. Nodeos showing following error,

Note -
I tried the same thing by providing the keys with binaryen also, but it flags the same error msg.
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.
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 end failing

3. Back end code and output

I would be really appreciate if you could guide for this ... Thanks in advance.
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.
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) => {

Please guide for the above error
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).
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.