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?