EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

EOSJS authorization #135

Closed mlawand closed 6 years ago

mlawand commented 6 years ago

I am following this tutorial https://github.com/eosasia/ping-eos I am trying to connect my web application to my smart contract. when i use cleos to test the smart contract i am able to see that the smart contract is functioning as it should

But when i try connecting to the application from the web app, i get this error.

[push_transaction error] '{"code":401,"message":"UnAuthorized","error":{"code":3030002,"name":"tx_missing_sigs","what":"signatures do not satisfy declared authorizations","details":[{"message":"transaction declares authority '{\"actor\":\"tester\",\"permission\":\"active\"}', but does not have signatures for it.","file":"chain_controller.cpp","line_number":1231,"method":"check_authorization"},{"message":"","file":"chain_controller.cpp","line_number":339,"method":"_push_transaction"},{"message":"","file":"chain_controller.cpp","line_number":291,"method":"push_transaction"}]}}', transaction '54340d5b189be9bc591800000000010000003723c0a6ab0000000000c0a6ab010000000000ea305500000000a8ed3232080000000000ea305500'

jcalfee commented 6 years ago

Recently added in EOSIO/eos is the chainId ..

Check: cleos get info .. If the chainId is not 706a7ddd808de9fc2b8879904f3b392256c83104c1d544b38302cc07d9fca477 you'll need to put your chainId in the config: Eos.Localnet({chainId: ...}).

mlawand commented 6 years ago

@jcalfee i have updated the config to const EOS_CONFIG = { contractName: "ping.ctr", // Contract name contractSender: "tester", // User executing the contract (should be paired with private key) chainId : "706a7ddd808de9fc2b8879904f3b392256c83104c1d544b38302cc07d9fca477", clientConfig: { keyProvider: ['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'], // Your private key httpEndpoint: 'http://127.0.0.1:8888' // EOS http endpoint } } and i am still getting the same error

jcalfee commented 6 years ago

What version of eosio/eos are you running?

mlawand commented 6 years ago

@jcalfee how can i find out the exact version? i have checked the genesis.json file and the "initial_chain_id": "0000000000000000000000000000000000000000000000000000000000000000"

jcalfee commented 6 years ago

You can checkout the most recent version then run / re-run the build:

git checkout dawn-v4.2.0
jcalfee commented 6 years ago

In version 4.2 don't worry about the chain id .. it is still zeros and that is already in the code as a default.

mlawand commented 6 years ago

i have updated to the latest version and i have redeployed by contracts to the chain but now when i try to call the contract from cleos i get this issue

transaction executed locally, but may not be confirmed by the network yet

And i am still getting the same error in my webapp

jcalfee commented 6 years ago

transaction executed locally, but may not be confirmed by the network yet

It worked.. When you see the above you should not get an error at all..

mlawand commented 6 years ago

@jcalfee but i am not able to push any action to my contracts, is there a new way in 4.2 to push actions?

jcalfee commented 6 years ago

This may be a back-end issue, not sure if I can help you .. I did re-test something and I did not get this message "transaction executed locally, but may not be confirmed by the network yet" ..

I start my node using the Docker image in this repository:

cd docker
./up.sh

All calls to smart contracts are push actions. Push action is cleos terminology. A transfer is just a well known push action to the eosio.tocken contract. It is working with the docker image calling the token contract:

> Eos=require('./src'),eos=Eos.Localnet({keyProvider: ['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3']}),1
1
> eos.getCurrencyBalance('eosio.token', 'initb', 'SYS').then(r => console.log(r) )
..
> [ '1082.4720 SYS' ]

> eos.transfer('inita', 'initb', '2 SYS', 'memo')
...

> eos.getCurrencyBalance('eosio.token', 'initb', 'SYS').then(r => console.log(r) )
> [ '1084.4720 SYS' ]
frankli1224 commented 6 years ago

@mlawand Hi, Did you solve the problem, I have the same issue, If you do solve this problem, Can you help me share the solution? Thank you very much!