safe-global / safe-smart-account

Safe allows secure management of blockchain assets.
https://safe.global
GNU Lesser General Public License v3.0
1.84k stars 907 forks source link

calculateSafeTransactionHash function error response #688

Closed makarid closed 11 months ago

makarid commented 11 months ago

Description

Hello, there is a weird issue when i am trying to run the calculateSafeTransactionHash function. The thing is that, when i pass a correct address i am getting an error:

Error: invalid address (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.7.0) reason: 'invalid address', code: 'INVALID_ARGUMENT', argument: 'address', value: undefined

When i run the same function with an incorrect address i am getting the following error:

Error: invalid address (argument="address", value=0x, code=INVALID_ARGUMENT, version=address/5.7.0) reason: 'invalid address', code: 'INVALID_ARGUMENT', argument: 'address', value: 0x

So, when i pass a correct address the function returns value=undefined. When i pass an incorrect address the function returns the same message WITH the value displayed. I will share the code below.

Environment

Running locally with:

Steps to reproduce

I am sharing the code:

import {calculateSafeTransactionHash} from "@safe-global/safe-contracts"; import {Contract, ethers, Wallet} from "ethers"; import gnosisProxyAbi from "./abi/gnosisProxyAbi.json" assert {type: "json"}; import SafeProtocol, {EthersAdapter} from "@safe-global/protocol-kit"; import {configDotenv} from "dotenv";

configDotenv()

const provider = new ethers.providers.JsonRpcProvider(process.env.JSON_URL, 'optimism') const safeTransactionData = { to: "0x", data: "0xdata", value: 1, operation: 1, }

const etherAdapter = new EthersAdapter({ ethers, signerOrProvider: new Wallet(Wallet.createRandom().privateKey, provider) }) const Safe = SafeProtocol.default /*

/**

const res = calculateSafeTransactionHash(new Contract(process.env.MY_SAFE_ADDRESS,gnosisProxyAbi,provider),safeTransaction, (await provider.getNetwork()).chainId) console.log(res)

I am waiting for your response.Thanks

mmv08 commented 11 months ago

Please share a better code example. From your example, it's unclear what the type of variables you're passing to the function.

makarid commented 11 months ago

I just update the code @mmv08 . You can copy paste and run it (add the params on .env file). I have the below dependancies:

"dependencies": { "@safe-global/safe-contracts": "^1.4.1-build.0", "ethers": "^5.7.2", "@safe-global/safe-core-sdk-types": "^2.3.0", "@safe-global/safe-core-sdk": "^3.3.5", "@safe-global/protocol-kit": "^1.3.0", "dotenv": "^16.3.1" }

If you change the address param on the new Contract function and make an invalid one, you see that the message returns the value of the incorrect param but it is saying undefined if you add a correct address.

mmv08 commented 11 months ago

You're passing a safe-core-sdk transaction into the function. They're incompatible. You should look into the safe-core-sdk documentation on how to obtain a hash for the transaction.

makarid commented 11 months ago

What type of SafeTransaction i need to pass? Thank you

makarid commented 11 months ago

import {calculateSafeTransactionHash} from "@safe-global/safe-contracts"; import {Contract, ethers, Wallet} from "ethers"; import gnosisProxyAbi from "./abi/gnosisProxyAbi.json" assert {type: "json"}; import SafeProtocol, {EthersAdapter} from "@safe-global/protocol-kit"; import {configDotenv} from "dotenv"; import {OperationType} from "@safe-global/safe-core-sdk-types";

configDotenv()

const provider = new ethers.providers.JsonRpcProvider(process.env.JSON_URL, 'optimism')

const etherAdapter = new EthersAdapter({ ethers, signerOrProvider: new Wallet(Wallet.createRandom().privateKey, provider) }) const Safe = SafeProtocol.default /*

/*

const safeTransactionRaw = await safeSdk.createTransaction( { safeTransactionData })

const safeTransaction = { safeTxGas: 0, baseGas: 0, gasPrice: 0, gasToken: "0x", refundReceiver: "0x", nonce: safeTransactionRaw.nonce }

const keck = calculateSafeTransactionHash(new Contract(process.env.MY_SAFE_ADDRESS,gnosisProxyAbi,provider),safeTransaction, (await provider.getNetwork()).chainId) console.log(keck)

The above code, returns the same error. I changed the SafeTransactionType