Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Chaincode via UI: Error endorsing txn: rpc error: code = Aborted desc = failed to endorse transaction #1158

Open
PsychoPunkSage opened this issue Dec 20, 2023 · 0 comments

Comments

@PsychoPunkSage
Copy link

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::

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::

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant