1

I'm trying to create new safe wallet for my current wallet using deploySafe method. Following is my implementation:

import Safe, {
  SafeAccountConfig,
  SafeFactory,
  Web3Adapter,
  Web3AdapterConfig,
} from '@safe-global/protocol-kit';
import { Web3, Web3BaseProvider } from 'web3';

const web3 = new Web3(new Web3.providers.HttpProvider('https://polygon-rpc.com'));

const ethAdapter = new Web3Adapter({
  web3,
  signerAddress: SAFE_OWNER_ADDRESS,
});

const safeFactory = await SafeFactory.create({
  ethAdapter,
});
const signer = await ethAdapter.getSignerAddress();
const safeAccountConfig: SafeAccountConfig = {
  owners: [signer],
  threshold: 1,
};


await safeFactory.deploySafe({
  safeAccountConfig,
});

SAFE_OWNER_ADDRESS is valid because I can get balance in matics, but Web3 Library always throws following error:

Returned error: unknown account
InvalidResponseError: Returned error: unknown account
at Web3RequestManager._processJsonRpcResponse (/Users/macuser/Desktop/work/node-seedhunter/node_modules/web3-eth-contract/node_modules/web3-core/src/web3_request_manager.ts:363:11)
at Web3RequestManager.<anonymous> (node-seedhunter/node_modules/web3-eth-contract/node_modules/web3-core/src/web3_request_manager.ts:207:16)
at Generator.next (<anonymous>)
at fulfilled (node-seedhunter/node_modules/web3-eth-contract/node_modules/web3-core/lib/commonjs/web3_request_manager.js:21:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Can Someone please help what I am doing wrong here?

2 Answers 2

0

HttpProvider is deprecated. Try passing the URI directly to the Web3 constructor.

const web3 = new Web3("https://polygon-rpc.com");

Use WebsocketProvider for legacy browsers.

1
  • I got the same error(
    – Nick
    Commented Jul 31, 2023 at 9:31
0

you can add this line before sending transaction

web3.eth.accounts.wallet.add(privateKey);

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.