hyperledger / hyperledger/fabric-samples
Calling Chaincode via UI: Error endorsing txn: rpc error: code = Aborted desc = failed to endorse transaction
- Dominant language
- Go
- Stars
- 3k
- Forks
- 3.5k
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 6
Description
Hi,
I am calling fabric-smaples/asset-transfer-basic/chaincode-go using a UI.....
I have tested the calling of chaincode using both postman and commandline and is working all good for me.
***REPO LINK(UI):: https://github.com/PsychoPunkSage/Vivenns/tree/Hyperledger/5_ui_restapi***
Command::
```bash
curl --request POST \
--url http://localhost:3000/invoke \
--header 'content-type: application/x-www-form-urlencoded' \
--data = \
--data channelid=mychannel \
--data chaincodeid=basic \
--data function=createAsset \
--data args=Asset123 \
--data args=yellow \
--data args=54 \
--data args=Tom \
--data args=13005
```
**NOW THE ISSUE.....**
I have made a very simple UI to call **CreateAsset** function and wrote a simple JS code to fetch it.....
JS Code::
```javascript
const createAsset = () => {
fetch('http://localhost:3000/invoke', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
channelid: "mychannel",
chaincodeid: "basic",
function: "createAsset",
// args: `${document.getElementById('assetid').value} ${document.getElementById('assetcolor').value} ${document.getElementById('assetsize').value} ${document.getElementById('assetowner').value} ${document.getElementById('assetappraisedvalue').value}`,
args: [
document.getElementById('assetid').value,
document.getElementById('assetcolor').value,
document.getElementById('assetsize').value,
document.getElementById('assetowner').value,
document.getElementById('assetappraisedvalue').value,
]
}),
})
.then((response) => {
return response.text();
})
.then((data) => {
console.log('Create Asset Response:', data);
document.getElementById('create-asset-response').value = data;
})
// .catch(error => {
// console.error('Error creating asset:', error);
// // document.getElementById('create-asset-response').value = `Error:: ${error}`;
// });
}
```
Error I'm getting
``` bash
Create Asset Response: Error endorsing txn: rpc error: code = Aborted desc = failed to endorse transaction
```
I have made some changes in **fabric-smaples/asset-transfer-basic/rest-api-go/web/invoke.go** to avoid ***CORS***
```go
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
w.Header().Set("Access-Control-Allow-Methods", "POST, HEAD, PATCH, OPTIONS, GET, PUT")
```
I have followed the same steps for **GetAllAssets** function, and it worked without any error.... But Here it is giving me Error I don't know why..
Please help in this regard...
Thank You
Contributor guide
Assessment
This issue has not been assessed yet.