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

Create signedTransaciton locally #905

Closed
soichisumi opened this issue Jun 1, 2018 · 5 comments
Closed

Create signedTransaciton locally #905

soichisumi opened this issue Jun 1, 2018 · 5 comments

Comments

@soichisumi
Copy link

soichisumi commented Jun 1, 2018

Is there any method to create signedTransaction locally?

I want to create signed transaction without connection with ripple server.
like:

api.preparePayment(address, payment)
    .then(prepared => {
        const signRes = api.sign(prepared.txJSON, secret);
    }).catch(fail);

I already succeeded to create and send a signed transaction like the following snippet:

api.connect().then(()=>{
     console.log('connected...');
     return api.preparePayment(address, payment, instructions).then(prepared => {
         console.log('Payment transaction prepared....');
        
         const signRes = api.sign(prepared.txJSON, secret);
         console.log('Payment transaction signed....');
         const txHash = signRes.id;
         console.log(`txhash: ${txHash}`);
         api.submit(signRes.signedTransaction).then(quit, fail);
     });
 }).catch(fail);
@intelliot
Copy link
Collaborator

Yes. The sign() method works without a connection to a ripple server. You need to provide all of the transaction instructions like the sequence number, fee, etc.

@soichisumi
Copy link
Author

I understood preparePayment() need to connect internet to correct information of ripple network.
So if I correct information(like fee, etc) beforehand, no need to connect internet in signing.

I succeed to sign transaction like this snippet:

const txJSON = '{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"726970706C652E636F6D","LastLedgerSequence":8820051,"Fee":"12","Sequence":23}';
var r = api.sign(txJSON, secret);

Thank you for your advice, @intelliot !

@intelliot
Copy link
Collaborator

intelliot commented Jun 1, 2018

@yoyoyousei Cool - that works. Note that writing txJSON that way requires using the rippled API's transaction format. The preparePayment() and most other prepare* methods can be used offline if you specify the fee, sequence, and maxLedgerVersion parameters. See this page: Offline functionality.

@soichisumi
Copy link
Author

soichisumi commented Jun 2, 2018

@intelliot wow. So if I fee, sequence and maxLedgerVersion specified in instructions, txJson is generated in offline.
I'll try it. Thank you for additional information!

@soichisumi
Copy link
Author

soichisumi commented Jun 26, 2018

As you said, I succeeded to get txJson in offline, by specifying fee, sequence and maxLedgerVersion in instructions. 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

2 participants