Git Product home page Git Product logo

Comments (4)

schimih avatar schimih commented on September 3, 2024

Hey @yagop ,

Can you provide more information? Maybe add an example of what you want to achieve?

from mx-sdk-js-core.

yagop avatar yagop commented on September 3, 2024

Hey @schimih sure, Imagine we have the tx hash (and the signature) but we need the Transaction object to be able to broadcast the tx.

import {
    Account,
    Address,
    TokenPayment,
    Transaction,
    TransactionVersion,
} from '@multiversx/sdk-core'
import { UserSecretKey, UserSigner } from '@multiversx/sdk-wallet'

const account = new Account(new Address(...));
const signer = new UserSigner(UserSecretKey.fromPem(...));

const tx = new Transaction({
    // ...
});
const serializedTransaction = tx.serializeForSigning();
const signature = await signer.sign(serializedTransaction);
// In other part of the code
function broadcastTx(txhash: string, signature: string) {
  
}

The sendTransaction(tx: ITransaction) method requires a ITransaction interface.

from mx-sdk-js-core.

yagop avatar yagop commented on September 3, 2024

Bump 😅

from mx-sdk-js-core.

andreibancioiu avatar andreibancioiu commented on September 3, 2024

Hello @yagop,

The transaction hash is a 32-byte sequence. Signature is a 64-byte sequence. Neither can be used to recover the transaction object (theoretically & practically impossible).

Perhaps there's the confusion that txHash and signature are serialized representations of a transaction? They are not. They are artifacts obtained through content hashing / computing digital signatures.

Simply use the same tx object to broadcast the transaction:

// Your code
const tx = new Transaction({
    // ...
});
const serializedTransaction = tx.serializeForSigning();
const signature = await signer.sign(serializedTransaction);

// New code
tx.applySignature(signature);
await networkProvider.sendTransaction(tx);

tx (as a Transaction) follows the ITransaction interface (they are compatible).

Also, make sure to have a look on the Cookbook:

https://docs.multiversx.com/sdk-and-tools/sdk-js/sdk-js-cookbook/

from mx-sdk-js-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.