3

I'm trying to manually forge a transaction, sign it with Beacon Wallet and inject it.

I've forged and sign it. preapplyOperations is OK.

Now I'm trying to build the input data for injectOperation using all I got from previous steps.

// 1. operation
    const operation = {
        branch: branch,
        contents: [
            {
                kind: opTxKind,
                source: userAddress,
                destination: userAddress,
                amount: "1",
                fee: estimated.suggestedFees,
                counter: counter,
                gas_limit: estimated.gasLimit,
                storage_limit: estimated.storageLimit
            }
        ]
    };
    
    // 2. forge operation
    const forgedBytes: string = await Tezos.rpc.forgeOperations(operation);
    
    // 3. sign with beacon wallet
    const payload: RequestSignPayloadInput = {
        signingType: SigningType.OPERATION,
        payload: '03' + forgedBytes,
        sourceAddress: userAddress,
    };

    const signedPayload = await wallet.client.requestSignPayload(payload);
    const { signature } = signedPayload; // get the edsig... signature
    
    // 4. preapply
    const preapplyParams = { ...operation, protocol, signature };
    const preapplyResponse = await Tezos.rpc.preapplyOperations([preapplyParams]);
    

As explained here (https://ocamlpro.com/blog/2018_11_21_an_introduction_to_tezos_rpcs_signing_operations), I try to do that:

const opHash = await Tezos.rpc.injectOperation(forgedBytes + b58decode(signature));
    

But it does not work:

HttpResponse: Http error response: (500) [{"kind":"temporary","id":"failure","msg":"Invalid operation opQM3tVn6UgLjcDTFJ5fdsR3oaDhGgRVaknCitovMJMJQNeHH6R: \nError:\n  Operation parsing error in prevalidation.\n."}]

Can you help me to create the input ?

1 Answer 1

2

Make sure you slice the prefix from the signature

The example bellow can be improved.

export const sign = async (wallet: BeaconWallet, bytes: string) => {
    const result = await wallet.client.requestSignPayload({
        signingType: SigningType.OPERATION,
        payload: '03' + bytes,
    });

    let sbytes = bs58check.decode(result.signature);
    if (result.signature.startsWith('edsig') || result.signature.startsWith('spsig1')) {
        sbytes = sbytes.slice(5).toString('hex');
    } else if (result.signature.startsWith('p2sig')) {
        sbytes = sbytes.slice(4).toString('hex');
    } else {
        sbytes = sbytes.slice(3).toString('hex');
    }

    return `${bytes}${sbytes}`;
};
const opHash = await Tezos.rpc.injectOperation(sign(...));
1
  • 1
    Thank you very much!
    – avl
    Oct 9, 2022 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.