How to pass signedTransaction to Server and then submitting

I want to generate a signedTransaction from web client side, send the signedTransaction to server side, where I do some additional handling and then broadcast it.

Everything works fine if I submit from client side. Like this

let txn = algosdk.makeAssetCreateTxnWithSuggestedParams(accountAddr, note, totalSupply, decimals, defaultFrozen, managerAddress, reserveAddress, freezeAddress, clawbackAddress, unitName, assetName, assetURL, "", getParams);
let signedTxn = txn.signTxn(thisAccount.sk);
var postTransactionUrl = "https://testnet.algoexplorerapi.io/v2/transactions";
var reqOptions = {
    method: "POST",
    headers: {
	 "Content-Type": "application/x-binary",
    },
    body: signedTxn
};
const txDetails = await (await fetch(postTransactionUrl, reqOptions)).json();

But when I pass the signedTransaction to my server via an https endpoint, the signedTxn somehow gets messed up and I get an error msg “msgpack decode error [pos 1]: only encoded map or array can be decoded into a struct”

// client side
let txn = algosdk.makeAssetCreateTxnWithSuggestedParams(accountAddr, note, totalSupply, decimals, defaultFrozen, managerAddress, reserveAddress, freezeAddress, clawbackAddress, unitName, assetName, assetURL, "", getParams);
let signedTxn = txn.signTxn(thisAccount.sk);
const createAsset = firebase.functions().httpsCallable("createAsset");
createAsset({
    "mode": "test",
    "signedTxn": signedTxn
});
//server side
exports.createAsset = functions.https.onCall(async (data, context) => {
var postTransactionUrl = "https://testnet.algoexplorerapi.io/v2/transactions";
var reqOptions = {
    method: "POST",
    headers: {
	 "Content-Type": "application/x-binary",
    },
    body: data.signedTxn
};
const txDetails = await (await fetch(postTransactionUrl, reqOptions)).json();
});

Ive tried JSON stringify on client then JSON parse on server side, I’ve tried the algosdk.decodeObj then algosdk.encodeObj. But nothing works. Anyone else have similar problems?

Check this out… AWallet is open source PWA wallet… in the source you can find how to send payment, payments of assets, opt in for asset, create asa, and more… :slight_smile:

This unfortunately isn’t what I was asking… In the code you provided, the signedTxn is signed and then broadcasted with the algodclient. (all in the same function)

I’m asking about instances where the signedTxn is send over https as a part of JSON object, then broadcasted on the other endpoint. My experience has been that the signedTxn object somehow becomes misformatted.

i think the issue is with the UInt8Array …

check this how i transfer the multisignature message from one computer to another using for example qr codes…

Ok seems like this has something to do with Google Cloud Functions (Firebase functions) imposing header {content-type: application/json} so the signedTxn becomes misformatted.

Just a heads up for anyone else who ever runs into this.

1 Like