0

I Have followed the suggested answers for the same issue in Getting ''Error: Unprocessable Entity" while calling 'safeService.proposeTransaction()'.

Even after that, the issue is not solved. Please kindly help me.

The code is :

import "./App.css";
import { ethers } from "ethers";
import EthersAdapter from "@safe-global/safe-ethers-lib";
import { useState, useEffect } from "react";
import SafeServiceClient from "@safe-global/safe-service-client";

import Safe, { SafeFactory } from "@safe-global/safe-core-sdk";
import { SafeTransactionDataPartial } from "@safe-global/safe-core-sdk-types";

// require("dotenv").config();

// const gnosis = async () => {
//   console.log("Hello");
// };
const gnosis = async () => {
  // const txServiceUrl = "https://safe-transaction-mainnet.safe.global";
  const safeAddress = "0xF05F8bc8a0D5FE5d2Eb2fB1d0F900b20E71dD966";

  // const {
  //   SafeFactory,
  //   SafeAccountConfig,
  //   ContractNetworksConfig,
  // } = require("@gnosis.pm/safe-core-sdk");
  // const Safe = require("@gnosis.pm/safe-core-sdk")["default"];

  // const EthersAdapter = require("@gnosis.pm/safe-ethers-lib")["default"];

  console.log("Hello");
  const provider = new ethers.providers.Web3Provider(window.ethereum, "any");
  console.log({ provider });
  await provider.send("eth_requestAccounts", []);
  const safeOwner = provider.getSigner();

  console.log("Meta mask address is ", safeOwner.getAddress(0));
  const address = await safeOwner.getAddress();
  console.log("ABC", address);

  const ethAdapter = new EthersAdapter({
    ethers,
    signerOrProvider: safeOwner,
  });
  const txServiceUrl = "https://safe-transaction-goerli.safe.global";
  const safeService = new SafeServiceClient({ txServiceUrl, ethAdapter });
  // const balances = await safeService.getBalances(safeAddress);
  // console.log(balances);
  const safeSdk = await Safe.create({ ethAdapter, safeAddress });
  const safeSdk2 = await safeSdk.connect({ ethAdapter, safeAddress });
  console.log("Please find the owners here", await safeSdk2.getOwners());
  const tocks = ethers.utils.getAddress(
    "0x1451Ec73259CCe92361f7Edb592DaEff947Df403"
  );
  const nonce = await safeService.getNextNonce(safeAddress);
  console.log("Nonce", nonce);
  const data1 = {
    to: tocks,
    data: "0xa9059cbb000000000000000000000000de7c0527b4b43bcbba09c4fbb8b9053156c23197000000000000000000000000000000000000000000000000000000000000000a",
    value: 0,
    nonce: nonce,
  };
  const safeTransactionData = data1;
  const safeTransaction = await safeSdk.createTransaction({
    safeTransactionData,
  });
  console.log(safeTransaction);
  const safeTxHash = await safeSdk.getTransactionHash(safeTransaction);
  // const signedSafeTransaction = await safeSdk.signTransaction(
  //   safeTransaction,
  //   "eth_sign"
  // );

  const senderSignature = await safeSdk.signTransactionHash(safeTxHash);
  console.log({ safeAddress }, 1);
  console.log("Safe Transaction", safeTransaction, 2);
  console.log({ safeTxHash }, 3);
  console.log({ address }, 4);
  console.log(senderSignature.data, 5);
  try {
    await safeService.proposeTransaction({
      safeAddress,
      safeTransactionData: safeTransaction.data,
      safeTxHash,
      senderAddress: address,
      senderSignature: senderSignature.data,
      origin: "",
    });
  } catch (err) {
    console.log({ err });
  }

  console.log("Proposed transaction completed");
  // const txResponse = await safeSdk.approveTransactionHash(txHash);
  // await txResponse.transactionResponse?.wait();
  // console.log({ signedSafeTransaction });
  const ownerAddresses = await safeSdk.getOwnersWhoApprovedTx(safeTxHash);
  console.log("All owners approved", ownerAddresses);
};
// 0x1451Ec73259CCe92361f7Edb592DaEff947Df403
// value : 0
// data : 0xa9059cbb000000000000000000000000de7c0527b4b43bcbba09c4fbb8b9053156c23197000000000000000000000000000000000000000000000000000000000000000a
//        ; 0x0000000000000000000000000000000000000000
// Nonce : 211

export default function App() {
  // const safeOwner = provider.getSigner(0);

  // const ethAdapter = new EthersAdapter({
  //   ethers,
  //   signerOrProvider: safeOwner,
  // });

  return (
    <div className="App">
      <h1>Hello</h1>
      <button onClick={gnosis}> Click here</button>
    </div>
  );
}

1 Answer 1

0

Try to set value as as a string. Like this:

const data1 = {
  to: tocks,
  data: "0xa9059cbb000000000000000000000000de7c0527b4b43bcbba09c4fbb8b9053156c23197000000000000000000000000000000000000000000000000000000000000000a",
  value: "0", // update this line
  nonce: nonce,
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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