-
-
Save aaroncox/102a70a9a6a37a9c2a90b6fabfbc86e7 to your computer and use it in GitHub Desktop.
// A custom cosigner AuthorityProvider for EOSJS v2
// This provider overrides the checks on all keys,
// allowing a partially signed transaction to be
// broadcast to the API node.
class CosignAuthorityProvider {
async getRequiredKeys(args) {
const { transaction } = args;
// Iterate over the actions and authorizations
transaction.actions.forEach((action, ti) => {
action.authorization.forEach((auth, ai) => {
// If the authorization matches the expected cosigner
// then remove it from the transaction while checking
// for what public keys are required
if (
auth.actor === 'greymassfuel'
&& auth.permission === 'cosign'
) {
delete transaction.actions[ti].authorization.splice(ai, 1)
}
})
});
return convertLegacyPublicKeys((await rpc.fetch('/v1/chain/get_required_keys', {
transaction,
available_keys: args.availableKeys,
})).required_keys);
}
}
// Pass in new authorityProvider
const api = new Api({
authorityProvider: new CosignAuthorityProvider(),
// the rest of your configuration
});
const { Api, JsonRpc } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
const { convertLegacyPublicKeys } = require('eosjs/dist/eosjs-numeric');
const privateKey = process.env.PRIVATE_KEY_EOS;
const signatureProvider = new JsSignatureProvider([privateKey]);
// Set up the API and JSON-RPC objects
const rpc = new JsonRpc('https://api.bitmars.one');
class CosignAuthorityProvider {
async getRequiredKeys(args) {
const { transaction } = args;
// Iterate over the actions and authorizations
transaction.actions.forEach((action, ti) => {
action.authorization.forEach((auth, ai) => {
// If the authorization matches the expected cosigner
// then remove it from the transaction while checking
// for what public keys are required
if (
auth.actor === "greymassfuel"
&& auth.permission === "cosign"
) {
delete transaction.actions[ti].authorization.splice(ai, 1)
}
})
});
return convertLegacyPublicKeys((await rpc.fetch('/v1/chain/get_required_keys', {
transaction,
available_keys: args.availableKeys,
})).required_keys);
}
}
const api = new Api({ authorityProvider: new CosignAuthorityProvider(), rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const eosSwap = async () => {
console.log('======EOS=======')
// Call the contract
try {
const result = await api.transact({
actions: [{
account: "greymassnoop",
name: "noop",
authorization: [{
actor: "greymassfuel",
permission: "cosign"
}],
data: {}
},
{
account: "eosio.token",
name: "transfer",
authorization: [{
actor: "hubenokdevel",
permission: "active"
}],
data: {
from: "hubenokdevel",
to: "fuel.gm",
quantity: "0.0020 EOS",
memo: "Fuel Transaction Fee | ref=teamg..."
}
},
{
account: "hubenokdevel",
name: "buytoken",
authorization: [{
actor: 'hubenokdevel',
permission: 'active',
}],
data: {
user: "hubenokdevel",
eos_amount: "0.1000 EOS",
id_pool: 12,
token_amount_per_native: "0.866 U",
slippage_bips: 100,
platform_fee_bips: 2000,
gas_estimate: 20,
recipient: "eosviralswap"
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(result);
} catch (error) {
console.error(error);
}
}
module.exports = {
eosSwap
}
this is my code and it's not working.
eosjs version is 22.1.0
RpcError: transaction declares authority '{"actor":"greymassfuel","permission":"cosign"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], provided keys ["EOS54itY6cctjQP6pzNkuzdBfVKFjf7You8o1CbguhU66Ays4yBmp"], and a delay max limit of 3888000000 ms
Hi @aaroncox I have exactly the same issue, Did you find the way to solve it??
I hope it worked