An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 10, 2022 03:40 am GMT
Original Link: https://dev.to/christianerdtmann/web3-be-the-msgsender-of-a-functioncall-to-a-smart-contract-returned-error-unknown-account-2nbj
Web3 be the msg.sender of a functioncall to a Smart Contract - Returned error: unknown account
Hello, i trying to call the function getRewards() from this contract:
https://polygonscan.com/address/0x4AB071C42C28c4858C4BAc171F06b13586b20F30#code
This function use msg.sender to give me the rewards to my accounts.
What i need to do that iam the message sender.
This is my code at the moment:
Web3 = require('web3')const fs = require('fs');const web3 = new Web3("https://polygon-rpc.com")const contractAddress = "0x4AB071C42C28c4858C4BAc171F06b13586b20F30"const contractJson = fs.readFileSync('./abi.json')const abi = JSON.parse(contractJson)const mSandMaticContract = new web3.eth.Contract(abi, contractAddress)asyncCall()async function asyncCall() { await mSandMaticContract.methods.getReward().send({ from: '0x560CC2be59c5deF53431783C3583B8f9F63b7793' })}
Maybe this is allready correct but i get the error:
Error: Returned error: unknown account
Any idea how to solve it?
I think i need to add to from a account instead of my public key so i tried:
web3.eth.accounts.privateKeyToAccount('PRIVATE_KEY');
but if i try to access the account with
var accounts = await web3.eth.getAccounts()console.log(accounts[0])
or
console.log(await web3.eth.accounts[0])
i just get beck "undefined".
Original Link: https://dev.to/christianerdtmann/web3-be-the-msgsender-of-a-functioncall-to-a-smart-contract-returned-error-unknown-account-2nbj
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To