safe-global / safe-core-sdk

The Safe{Core} SDK allows builders to add account abstraction functionality into their apps.
https://docs.safe.global/sdk/overview
MIT License
253 stars 193 forks source link

Getting ''Error: Unprocessable Entity" while calling 'safeService.proposeTransaction()' #164

Open jb3008 opened 2 years ago

jb3008 commented 2 years ago

Describe the bug Error: Unprocessable Entity at sendRequest (C:\Home\Mesha\mesha-be\node_modules\@gnosis.pm\safe-service-client\src\utils\httpRequests.ts:52:9) at processTicksAndRejections (internal/process/task_queues.js:97:5)

To Reproduce

import SafeServiceClient from "@gnosis.pm/safe-service-client";
const safeService = new SafeServiceClient('https://safe-transaction.rinkeby.gnosis.io');
import Safe, { EthersAdapter } from "@gnosis.pm/safe-core-sdk";
import { ethers } from "ethers";
const HDWalletProvider = require("@truffle/hdwallet-provider");

// Creating web3 provider
const walletProvider = new HDWalletProvider({
  privateKeys: [privateKey], 
  providerOrUrl: ALCHEMY_KEY,
});

const provider = new ethers.providers.Web3Provider(walletProvider);

// Initializing safe-core sdk
const signer: any = provider.getSigner(0);

const ethAdapter = new EthersAdapter({
  ethers,
  signer,
});

const safeSdk: Safe = await Safe.create({ ethAdapter, safeAddress }); // safeAddress: '0x0A3dAaa3AEbd9A832b87FC94F1aBc15a9e4ed6F5', Rinkeby

const transaction = {
  to: '0xb0968a944aF335f0f73900821a52d0066593aC5a',
  data: '0x',
  value: '1000000000000000',
}
transaction.nonce = await safeService.getNextNonce(safeAddress);
const safeTransaction = await safeSdk.createTransaction(transaction);
await safeSdk.signTransaction(safeTransaction);
const safeTxHash = await safeSdk.getTransactionHash(safeTransaction);
await safeService.proposeTransaction({
  safeAddress,
  safeTransaction,
  safeTxHash,
  senderAddress,
}); // Here I am getting the error

Expected behavior

safeAddress: '0x0A3dAaa3AEbd9A832b87FC94F1aBc15a9e4ed6F5'
safeTransaction: EthSafeTransaction {
  signatures: Map {
    '0xb0968a944af335f0f73900821a52d0066593ac5a' => EthSignSignature {
      signer: '0xb0968a944aF335f0f73900821a52d0066593aC5a',
      data: '0xc6eb0fed77c6c6bf3891aa06f6620b0cc53a4646633dfd3148d16868fa45c58d53cdb1359ceabdaddab2cf37e8ca1997ab19669776b75
    }
  },
  data: {
    to: '0xb0968a944af335f0f73900821a52d0066593ac5a',
    value: '1000000000000000',
    data: '0x',
    operation: 0,
    baseGas: 0,
    gasPrice: 0,
    gasToken: '0x0000000000000000000000000000000000000000',
    refundReceiver: '0x0000000000000000000000000000000000000000',
    nonce: 0,
    safeTxGas: 0
  }
}
safeTxHash: '0x0954a44ef78e4a0cdeabbafb196dd2ab7ee531739c3ecd58636804571fd868ab'
senderAddress: '0xb0968a944aF335f0f73900821a52d0066593aC5a'

Environment (please complete the following information): @gnosis.pm/safe-core-sdk: v1.3.0 @gnosis.pm/safe-service-client: v1.1.1 node: v12.17.0 @truffle/hdwallet-provider: v2.0.0 ethers: v5.5.3

germartinez commented 2 years ago

Hi @jb3008, can you please check in the dev console > network tab if there is another other message in the same response explaining the reason for that given "Unprocessable Entity"?

mmv08 commented 2 years ago

It was related to the recipient address not being checksummed. We should either throw an error or checksum in the SDK

jb3008 commented 2 years ago

Thanks resolved

adam-maj commented 1 year ago

@jb3008 which address wasn't checksummed here out of curiosity? running into the same error. it looks like in the original message, the to address an safeAddress were both checksummed properly?