Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculateSafeTransactionHash function error response #688

Closed
makarid opened this issue Oct 27, 2023 · 5 comments
Closed

calculateSafeTransactionHash function error response #688

makarid opened this issue Oct 27, 2023 · 5 comments

Comments

@makarid
Copy link

makarid commented Oct 27, 2023

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:

  • Compiler version: Node.js v20.3.1
  • Operating system: Ubuntu 22
  • i have install it with the following command: npm i @safe-global/safe-contracts --legacy-peer-deps , because i have already the 5.7.2 version of etherjs on my project.

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
/**
*

  • @type {Safe}
    */
    const safeSdk = await Safe.create({ ethAdapter: etherAdapter, safeAddress: process.env.MY_SAFE_ADDRESS })

/**
*

  • @type {SafeTransaction}
    */
    const safeTransaction = await safeSdk.createTransaction( {
    safeTransactionData: safeTransactionData,
    options: {
    value: 1,
    }
    })

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
Copy link
Member

mmv08 commented Oct 27, 2023

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

@makarid
Copy link
Author

makarid commented Oct 27, 2023

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
Copy link
Member

mmv08 commented Oct 27, 2023

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.

@mmv08 mmv08 closed this as completed Oct 27, 2023
@makarid
Copy link
Author

makarid commented Oct 27, 2023

What type of SafeTransaction i need to pass? Thank you

@makarid
Copy link
Author

makarid commented Oct 27, 2023

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
/**
*

  • @type {Safe}
    */
    const safeSdk = await Safe.create({ ethAdapter: etherAdapter, safeAddress: process.env.MY_SAFE_ADDRESS })

/**
*

  • @type {SafeTransactionDataPartial}
    */
    const safeTransactionData = {
    to: process.env.MY_SAFE_ADDRESS,
    data: "0x",
    value: 1,
    operation: OperationType.DelegateCall,
    }

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants