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

Wallet property not copied from context passed in Web3 constructor #6659

Closed
mpetrunic opened this issue Dec 13, 2023 · 0 comments · Fixed by #6661
Closed

Wallet property not copied from context passed in Web3 constructor #6659

mpetrunic opened this issue Dec 13, 2023 · 0 comments · Fixed by #6661
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@mpetrunic
Copy link
Contributor

Expected behavior

Should work

Actual behavior

errors with unknown account because wallet isn't copied from web3 instance to contract context.

Steps to reproduce the behavior

import { Contract, Web3 } from "web3";
import abi from "./contractabi.json" assert { type: "json" };

(async () => {
  const web3 = new Web3(
    "https://rpc2.sepolia.org"
  );

  const account = web3.eth.accounts.wallet
    .add("Private Key")
    .get(0);

  console.log(web3.wallet);

  const contract = new Contract(
    abi,
    "0x7af963cF6D228E564e2A0aA0DdBF06210B38615D",
    web3
  );

  //@ts-expect-error
  const receipt = await contract.methods.store("test")

  console.log(await receipt.send({from: account?.address}));
})();

https://github.com/web3/web3.js/blob/4.x/packages/web3-core/src/web3_context.ts#L131
probably "_wallet" should be copied instead of "wallet" because getter isn't copied here: https://github.com/web3/web3.js/blob/4.x/packages/web3-eth-contract/src/contract.ts#L482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
3 participants