<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ChristianErdtmann</title>
    <description>The latest articles on DEV Community by ChristianErdtmann (@christianerdtmann).</description>
    <link>https://dev.to/christianerdtmann</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F844898%2Fec4d38b4-ac0c-48da-b5cb-72994f149c8b.png</url>
      <title>DEV Community: ChristianErdtmann</title>
      <link>https://dev.to/christianerdtmann</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/christianerdtmann"/>
    <language>en</language>
    <item>
      <title>Web3 be the msg.sender of a functioncall to a Smart Contract - Returned error: unknown account</title>
      <dc:creator>ChristianErdtmann</dc:creator>
      <pubDate>Sun, 10 Apr 2022 03:40:57 +0000</pubDate>
      <link>https://dev.to/christianerdtmann/web3-be-the-msgsender-of-a-functioncall-to-a-smart-contract-returned-error-unknown-account-2nbj</link>
      <guid>https://dev.to/christianerdtmann/web3-be-the-msgsender-of-a-functioncall-to-a-smart-contract-returned-error-unknown-account-2nbj</guid>
      <description>&lt;p&gt;Hello, i trying to call the function getRewards() from this contract:&lt;br&gt;
&lt;a href="https://polygonscan.com/address/0x4AB071C42C28c4858C4BAc171F06b13586b20F30#code"&gt;https://polygonscan.com/address/0x4AB071C42C28c4858C4BAc171F06b13586b20F30#code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This function use msg.sender to give me the rewards to my accounts.&lt;br&gt;
What i need to do that iam the message sender.&lt;/p&gt;

&lt;p&gt;This is my code at the moment:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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' })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Maybe this is allready correct but i get the error:&lt;/p&gt;

&lt;p&gt;Error: Returned error: unknown account&lt;/p&gt;

&lt;p&gt;Any idea how to solve it?&lt;/p&gt;

&lt;p&gt;I think i need to add to from a account instead of my public key so i tried:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web3.eth.accounts.privateKeyToAccount('PRIVATE_KEY');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;but if i try to access the account with &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var accounts = await web3.eth.getAccounts()
console.log(accounts[0])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(await web3.eth.accounts[0])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;i just get beck "undefined".&lt;/p&gt;

</description>
      <category>smartcontract</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>QuickSwap/UniSwap Swap-Automation Web3</title>
      <dc:creator>ChristianErdtmann</dc:creator>
      <pubDate>Sat, 09 Apr 2022 23:08:27 +0000</pubDate>
      <link>https://dev.to/christianerdtmann/quick-swap-automation-web3-2g5c</link>
      <guid>https://dev.to/christianerdtmann/quick-swap-automation-web3-2g5c</guid>
      <description>&lt;p&gt;Hey i want to automate in javascript my interactions with QuickSwap.&lt;br&gt;
In the first step i just want to swap SAND to MATIC. (&lt;a href="https://quickswap.exchange/#/swap"&gt;https://quickswap.exchange/#/swap&lt;/a&gt;)&lt;br&gt;
In the secound step i want to add Liqudity to mSand-Matic Pool&lt;br&gt;
(&lt;a href="https://quickswap.exchange/#/add/ETH/0xBbba073C31bF03b8ACf7c28EF0738DeCF3695683"&gt;https://quickswap.exchange/#/add/ETH/0xBbba073C31bF03b8ACf7c28EF0738DeCF3695683&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;How to do this?&lt;/p&gt;

&lt;p&gt;Edit:&lt;br&gt;
I trying now the following but for some reason it doesn work. PLEASE HELP :)&lt;/p&gt;

&lt;p&gt;I get no error i get only back some information from the blockchain like you can see on the bottom.&lt;/p&gt;

&lt;p&gt;This is my code for reproduce:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const qs = require('quickswap-sdk')
    const ethers = require('ethers')
    Web3 = require('web3')
    const { Console } = require('console');
    const fs = require('fs')

const alchemy = 'https://polygon-mainnet.g.alchemy.com/v2/OfATG5uHb8ZdFbaCLfD79M236-hICOPz'
provider = new ethers.providers.JsonRpcProvider(alchemy)
const web3 = new Web3("https://polygon-rpc.com")

const contractAddressQuickSwapRouter = "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff"
const contractQuickSwapRouterJson = fs.readFileSync('./abiQuickSwapRouter.json')
const abiQuickSwapRouter = JSON.parse(contractQuickSwapRouterJson)
const quickSwapRouterContract = new web3.eth.Contract(abiQuickSwapRouter, contractAddressQuickSwapRouter)

asyncCall()

async function asyncCall() {

   //Swap Matic to Sand on Quick Swap
    getUnixCurrentTimestamp = Math.floor(Date.now() / 1000)
    getDeadlineAfter1Day = getUnixCurrentTimestamp + 86400
    console.log(getUnixCurrentTimestamp)

    wMaticAddress = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'
    mSandAddress = '0xBbba073C31bF03b8ACf7c28EF0738DeCF3695683'
    matic = await qs.Fetcher.fetchTokenData(137, wMaticAddress, provider)
    sand = await qs.Fetcher.fetchTokenData(137, mSandAddress, provider)
    pair = await qs.Fetcher.fetchPairData(matic, sand, provider)
    route = new qs.Route([pair], sand) //how much is sand in matic
    price = route.midPrice.toSignificant(6) //Parameter are Decimal Points

    amountSand = 0.05
    amountMatic = amountSand * price
    amountSandWEI = Math.round(amountSand * (10 ** 18)).toString()
    amountMaticWEI = Math.round(amountMatic * (10 ** 18)).toString()
    console.log(amountSand)
    console.log(amountMatic)

    encoded = quickSwapRouterContract.methods.swapExactTokensForTokens(amountSandWEI, amountMaticWEI, [mSandAddress], wMaticAddress, getDeadlineAfter1Day).encodeABI()
    block = await web3.eth.getBlock("latest");
    gasLimit = Math.round(block.gasLimit / block.transactions.length);

    var tx = {
        gas: gasLimit,
        to: publicKey,
        data: encoded
    }

    web3.eth.accounts.signTransaction(tx, privateKey).then(signed =&amp;gt; {
        web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
    })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I get this as log in my console:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node contract-interact.js
1649626258
0.05
0.1012595
{
  blockHash: '0xc2a10b99e045ec343251ceba3bcf6e2e0a565464f5b2569ef2733ce05a1c06ae',
  blockNumber: 26983103,
  contractAddress: null,
  cumulativeGasUsed: 10545837,
  effectiveGasPrice: '0x73ab4d2b0',
  from: '0x560cc2be59c5def53431783c3583b8f9f63b7793',
  gasUsed: 22656,
  logs: [
    {
      address: '0x0000000000000000000000000000000000001010',
      topics: [Array],
      data: '0x00000000000000000000000000000000000000000000000000027fcb82cf9f000000000000000000000000000000000000000000000000002f6238feb83b7611000000000000000000000000000000000000000000002c2dc38207aeea7fd51e0000000000000000000000000000000000000000000000002f5fb933356bd711000000000000000000000000000000000000000000002c2dc384877a6d4f741e',   
      blockNumber: 26983103,
      transactionHash: '0x61affa8dd44deb45ae3fa09d0b39468e6abd6af51e4fb9cf43eeb37ddf437d40',
      transactionIndex: 67,
      blockHash: '0xc2a10b99e045ec343251ceba3bcf6e2e0a565464f5b2569ef2733ce05a1c06ae',
      logIndex: 289,
      removed: false,
      id: 'log_20cccca0'
    }
  ],
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000080000000000000800000000000000000000000000000800000000000000000000100000000000100000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000010000000000000000000200000000000000000000000000000000000000000000000000000000000004000000000000000040001000000000000000000000000000000100000000000000000000000040000000000000000000000000000000000000000000000100000',
  status: true,
  to: '0x560cc2be59c5def53431783c3583b8f9f63b7793',
  transactionHash: '0x61affa8dd44deb45ae3fa09d0b39468e6abd6af51e4fb9cf43eeb37ddf437d40',
  transactionIndex: 67,
  type: '0x0'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Interact with existing Smart Contract</title>
      <dc:creator>ChristianErdtmann</dc:creator>
      <pubDate>Sat, 09 Apr 2022 23:04:48 +0000</pubDate>
      <link>https://dev.to/christianerdtmann/interact-with-existing-smart-contract-41e3</link>
      <guid>https://dev.to/christianerdtmann/interact-with-existing-smart-contract-41e3</guid>
      <description>&lt;p&gt;Hey i want to automate my staking on The Sandbox. For that i need in the first step to interact with the mSand-Matic Pool Contract. It is this one: &lt;a href="https://polygonscan.com/address/0x4ab071c42c28c4858c4bac171f06b13586b20f30#code"&gt;https://polygonscan.com/address/0x4ab071c42c28c4858c4bac171f06b13586b20f30#code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have written a little programm in a github repo to show what i have done see here: &lt;a href="https://github.com/ChristianErdtmann/mSandMaticStakingAutomation"&gt;https://github.com/ChristianErdtmann/mSandMaticStakingAutomation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or here the code example from the contract-interact.js&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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)
mSandMaticContract.balanceOf('0x7e5475290Df8E66234A541483453B5503551C780')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The abi i have taken from the contract link on the top. But it seems there is a problem.&lt;/p&gt;

&lt;p&gt;I tried for testing to read someting from the contract. For that i used the function balanceOf(address), how you can see in the code.&lt;/p&gt;

&lt;p&gt;But i get alltimes the error: TypeError: mSandMaticContract.balanceOf is not a function&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
