Goal: be able to separately create, sign and broadcast a transaction:
Global for both approaches:
const privkey = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3';
Approach 1:
transferSignPushTr1 : async (from, to, amount, memo) => {
const options = {
authorization: `${from}@active`, //@active for activeKey, @owner for Owner key
//default authorizations will be calculated.
broadcast: false,
sign: false,
};
const transaction = await eos.transaction(
'eosio.token',
acc => {
acc.transfer(from, to, amount, memo);
},
options
);
const data = transaction.transaction.transaction.actions[0].data;
const sig = await ecc.sign(data, privkey);
const trFinal = await eos.pushTransaction({ compression: 'none', transaction: transaction, signatures: sig })
},
returns "Invalid packed transaction"
Possible problem. Wrong transaction
file in eos.pushTransaction()
or wrong data
for ecc.sign(data, ...)
Approach 2:
transferSignPushTr2 : async (from, to, amount, memo) => {
const options = {
authorization: `${from}@active`, //@active for activeKey, @owner for Owner key
//default authorizations will be calculated.
broadcast: false,
sign: false,
};
const transaction = await eos.transaction(
'eosio.token',
acc => {
acc.transfer(from, to, amount, memo);
},
options
);
const data = transaction.transaction.transaction.actions[0].data;
const sig = await ecc.sign(data, privkey);
transaction.transaction.signatures.push(sig);
const trFinal = await eos.pushTransaction(transaction.transaction);
},
returns :
api < error { message:
'transaction declares authority \'{"actor":"inita","permission":"active"}\', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], and provided keys ["EOS7pDBdW8JeB8wxc9HyECgFtL3pYewYeimQ9uThoGLc1HE5cCikG"]',
file: 'authorization_manager.cpp',
line_number: 411,
possible problem:
ecc.sign()
hast the wrong input. I tried to generate a digest
as suggested here, but could not find the option in eosjs.
In https://github.com/EOSIO/eosjs/blob/v14.1.1/src/write-api.js#L406-L419 , a Buffer is used. I was not yet able to replicate it since I did not find the Transaction
object/arg.