greymass / greymassfuel-eosjs-demos

eosjs demos using the greymassfuel account and ONLY_BILL_FIRST_AUTHORIZER
7 stars 4 forks source link

I followed your code but it's not working. #7

Open gurujustin opened 1 year ago

gurujustin commented 1 year ago
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 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

I got this error

aaroncox commented 1 year ago

Try this method instead.

https://forums.eoscommunity.org/t/an-eosjs-based-example-for-the-initial-resource-provider-specification/2713

The approach to co-signing transactions has changed since this codebase was created years ago.

gurujustin commented 1 year ago

I already tried that example

jmgayosso commented 5 months ago

Hi @aaroncox @gurujustin I have exactly the same issue, Did you find the way to solve it?