0

I created a smart contract (lets call it MyContract) and deployed it on Mumbai testnet. I used this tutorial to connect to MyContract. this is my code:

import maticjs from '@maticnetwork/maticjs';
const { POSClient,use } = maticjs;
import maticjsWeb3 from '@maticnetwork/maticjs-web3';
const { Web3ClientPlugin } = maticjsWeb3;
import HDWalletProvider from "@truffle/hdwallet-provider";
import * as dotenv from 'dotenv'
dotenv.config()

// install web3 plugin
use(Web3ClientPlugin);

const posClient = new POSClient();

let fromAddress = "<my private address (also the miner of the contract)>";

await posClient.init({
    network: 'testnet',
    version: 'mumbai',
    parent: {
      provider: new HDWalletProvider(process.env.MNEMONIC, process.env.MUMBAI_RPC_URL)
    },
    child: {
      provider: new HDWalletProvider(process.env.MNEMONIC, process.env.MUMBAI_RPC_URL),
      defaultConfig: {
        from : fromAddress
      }
    }
});

const erc20ChildToken = posClient.erc20("<MyContract address>");

const balance = await erc20ChildToken.getBalance(fromAddress);
console.log('balance', balance/10**18);


const result = await erc20ChildToken.stake(10);
console.log('result ', result)

as you can see in the last 2 rows I have a call erc20ChildToken.stake by which I intended to call the stake function of the contract, but I get this error:

TypeError: erc20ChildToken.stake is not a function

How can I access "special" functions that are not part of the standard ERC20 interface?

1 Answer 1

0

You need to provide the correct ABI and create a contract with it. You can also use a low-level call but the better way is with the correct ABI.

3
  • how do I do that? can you share a code example? or maybe a guide online? haven't found anything good when I searched
    – orr
    Oct 20, 2022 at 6:46
  • Do you want it specific to maticJS or you don’t mind?
    – matank001
    Oct 20, 2022 at 7:49
  • I don't mind, as long as it works for polygon
    – orr
    Oct 23, 2022 at 6:33

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.