Gnosis-Safe

呼叫“safeService.proposeTransaction()”時出現“錯誤:無法處理的實體”

  • February 2, 2022

在向安全服務提出交易時,我收到以下錯誤:

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)

我正在使用以下程式碼在後端創建和提議交易:

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

所有的輸入對我來說似乎都很好,因為我在呼叫之前安慰了他們proposeTransaction

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'

錯誤不太有用,因為它沒有提供太多資訊。在前端使用安全 SDK 時,我沒有遇到此類錯誤。

版本:

@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

好的,問題解決了。原因是to事務中的欄位沒有校驗和:

const transaction = {
 to: '0xb0968a944aF335f0f73900821a52d0066593aC5a',
 data: '0x',
 value: '1000000000000000',
}

我檢查了地址並且它有效:

transaction.to = ethers.utils.getAddress(transaction.to)

我認為 SDK 應該處理這個問題,因為我在前端使用 SDK 時沒有遇到這個問題,甚至指南中沒有提到這個

引用自:https://ethereum.stackexchange.com/questions/120535