0

This below code is working fine in testnet. I want to do transaction, signing and broadcasting individually. I generated the raw transaction, but I don't understand how to sign it. I have provided the real working code and current console result.

const { Api, JsonRpc } = require('eosjs')
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig') // development only
const fetch = require('node-fetch') // node only
const { TextDecoder, TextEncoder } = require('util') // node only
const signatureProvider = new JsSignatureProvider([
    '5KAgjsrSrsXrsnxrpYY5ApAikfAEXYEVuvVhnakCQeS2KCb7dKq'
])
const rpc = new JsonRpc('http://jungle2.cryptolions.io:80', { fetch })
const ecc = require('eosjs-ecc')

const api = new Api({
    rpc,
    signatureProvider,
    textDecoder: new TextDecoder(),
    textEncoder: new TextEncoder()
})
const transaction = {
    actions: [
        {
            account: 'eosio.token',
            name: 'transfer',
            authorization: [
                {
                    actor: 'useraaaaaaax',
                    permission: 'active'
                }
            ],
            data: {
                from: 'useraaaaaaax',
                to: 'useraaaaazzz',
                quantity: '2.0000 EOS',
                memo: '25.11.2019 from x to zzz at'
            }
        }
    ]
}
const optionaldetails = {
    blocksBehind: 3,
    expireSeconds: 30,
    broadcast: false, //if this is true
    sign: false //if this is also true
    //then transaction is happening 
    //result can be seen here
    //click accountinfo and enter username either useraaaaaaax  or   useraaaaazzz
    // https://api.monitor.jungletestnet.io/#accountInfo
}


//for transaction
async function forTransaction() {
    console.log('inside transaction')
    let transactResult = await api.transact(transaction, optionaldetails)
    console.log('transactResult', transactResult)
}
forTransaction()

//console result
    inside transaction
    transactResult {
      serializedTransaction: Uint8Array [
        172,  99, 221,  93,  18, 167, 149, 245,  10, 150,   0,   0,
          0,   0,   1,   0, 166, 130,  52,   3, 234,  48,  85,   0,
          0,   0,  87,  45,  60, 205, 205,   1, 208, 141,  49, 198,
         24, 115,  21, 214,   0,   0,   0,   0, 168, 237,  50,  50,
         60, 208, 141,  49, 198,  24, 115,  21, 214, 240, 255,  55,
        198,  24, 115,  21, 214,  32,  78,   0,   0,   0,   0,   0,
          0,   4,  69,  79,  83,   0,   0,   0,   0,  27,  50,  53,
         46,  49,  49,  46,  50,  48,  49,  57,  32, 102, 114, 111,
        109,  32, 120,  32,
        ... 10 more items
      ],
      signatures: []
    }
  • Can you please try with sign: true, broadcast: true ( or even without them at all) and the address https://jungle2.cryptolions.io instead of http://jungle2.cryptolions.io:80 ? – Tigran Sahakyan Nov 27 '19 at 10:58
  • Its working, but I want to do all process individually. Read first line of question again – Er Deepak Garg Nov 27 '19 at 11:16
  • I got you, I think you should dig into your node_modules/eosjs/dist/*.js files, especially eosjs-api.js wher you'll find ``` case 10: requiredKeys = _g.sent(); return [4 /*yield*/, this.signatureProvider.sign({ chainId: this.chainId, requiredKeys: requiredKeys, serializedTransaction: serializedTransaction, abis: abis, })]; ``` signatureProvider has sing() – Tigran Sahakyan Nov 27 '19 at 11:34
  • I am trying hard for such a long time, not able to figure out properly – Er Deepak Garg Nov 27 '19 at 11:59
0

I am working only with eosjs@16.0.9 as in my opinion it is much more simple and easier to use. In v16.0.9 you can achieve your goal by doing the following:

// Generate a tx and sign it
const tx = (await eos.transaction({actions}, { broadcast: false, sign: true, keyProvider: signer.privateKey })).transaction;

// Broadcast the signed transaction
await eos.pushTransaction(tx);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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