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
Interact with existing Smart Contract
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: https://polygonscan.com/address/0x4ab071c42c28c4858c4bac171f06b13586b20f30#code
I have written a little programm in a github repo to show what i have done see here: https://github.com/ChristianErdtmann/mSandMaticStakingAutomation
Or here the code example from the contract-interact.js
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)console.log(mSandMaticContract)mSandMaticContract.balanceOf('0x7e5475290Df8E66234A541483453B5503551C780')
The abi i have taken from the contract link on the top. But it seems there is a problem.
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.
But i get alltimes the error: TypeError: mSandMaticContract.balanceOf is not a function
I dont know whats wrong there because i log the contract in my code and it seems for me the contract is found seccesfull. So why i cant interact with this function? What is missing?
And how you can see in the log the method balanceOf is found how we see on the line:
balanceOf: [Function: bound _createTxObject],
So why i cant use it?
Here is the Log:
PS C:\Users\erdtm\Documents\Blockchain Projects\mSandMaticStakingAutomation> node contract-interact.jsContract { setProvider: [Function (anonymous)], currentProvider: [Getter/Setter], _requestManager: RequestManager { provider: HttpProvider { withCredentials: false, timeout: 0, headers: undefined, agent: undefined, connected: false, host: 'https://polygon-rpc.com', httpsAgent: [Agent] }, providers: { WebsocketProvider: [Function: WebsocketProvider], HttpProvider: [Function: HttpProvider], IpcProvider: [Function: IpcProvider] }, subscriptions: Map(0) {} }, givenProvider: null, providers: { WebsocketProvider: [Function: WebsocketProvider], HttpProvider: [Function: HttpProvider], IpcProvider: [Function: IpcProvider] }, _provider: HttpProvider { withCredentials: false, timeout: 0, headers: undefined, agent: undefined, connected: false, host: 'https://polygon-rpc.com', httpsAgent: Agent { _events: [Object: null prototype], _eventsCount: 2, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object: null prototype], requests: [Object: null prototype] {}, sockets: [Object: null prototype] {}, freeSockets: [Object: null prototype] {}, keepAliveMsecs: 1000, keepAlive: true, maxSockets: Infinity, maxFreeSockets: 256, scheduling: 'lifo', maxTotalSockets: Infinity, totalSocketCount: 0, maxCachedSessions: 100, _sessionCache: [Object], [Symbol(kCapture)]: false } }, setRequestManager: [Function (anonymous)], BatchRequest: [Function: bound Batch], extend: [Function: ex] { formatters: { inputDefaultBlockNumberFormatter: [Function: inputDefaultBlockNumberFormatter], inputBlockNumberFormatter: [Function: inputBlockNumberFormatter], inputCallFormatter: [Function: inputCallFormatter], inputTransactionFormatter: [Function: inputTransactionFormatter], inputAddressFormatter: [Function: inputAddressFormatter], inputPostFormatter: [Function: inputPostFormatter], inputLogFormatter: [Function: inputLogFormatter], inputSignFormatter: [Function: inputSignFormatter], inputStorageKeysFormatter: [Function: inputStorageKeysFormatter], outputProofFormatter: [Function: outputProofFormatter], outputBigNumberFormatter: [Function: outputBigNumberFormatter], outputTransactionFormatter: [Function: outputTransactionFormatter], outputTransactionReceiptFormatter: [Function: outputTransactionReceiptFormatter], outputBlockFormatter: [Function: outputBlockFormatter], outputLogFormatter: [Function: outputLogFormatter], outputPostFormatter: [Function: outputPostFormatter], outputSyncingFormatter: [Function: outputSyncingFormatter] }, utils: { _fireError: [Function: _fireError], _jsonInterfaceMethodToString: [Function: _jsonInterfaceMethodToString], _flattenTypes: [Function: _flattenTypes], randomHex: [Function: randomHex], BN: [Function], isBN: [Function: isBN], isBigNumber: [Function: isBigNumber], isHex: [Function: isHex], isHexStrict: [Function: isHexStrict], sha3: [Function], sha3Raw: [Function: sha3Raw], keccak256: [Function], soliditySha3: [Function: soliditySha3], soliditySha3Raw: [Function: soliditySha3Raw], encodePacked: [Function: encodePacked], isAddress: [Function: isAddress], checkAddressChecksum: [Function: checkAddressChecksum], toChecksumAddress: [Function: toChecksumAddress], toHex: [Function: toHex], toBN: [Function: toBN], bytesToHex: [Function: bytesToHex], hexToBytes: [Function: hexToBytes], hexToNumberString: [Function: hexToNumberString], hexToNumber: [Function: hexToNumber], toDecimal: [Function: hexToNumber], numberToHex: [Function: numberToHex], fromDecimal: [Function: numberToHex], hexToUtf8: [Function: hexToUtf8], hexToString: [Function: hexToUtf8], toUtf8: [Function: hexToUtf8], stripHexPrefix: [Function: stripHexPrefix], utf8ToHex: [Function: utf8ToHex], stringToHex: [Function: utf8ToHex], fromUtf8: [Function: utf8ToHex], hexToAscii: [Function: hexToAscii], toAscii: [Function: hexToAscii], asciiToHex: [Function: asciiToHex], fromAscii: [Function: asciiToHex], unitMap: [Object], toWei: [Function: toWei], fromWei: [Function: fromWei], padLeft: [Function: leftPad], leftPad: [Function: leftPad], padRight: [Function: rightPad], rightPad: [Function: rightPad], toTwosComplement: [Function: toTwosComplement], isBloom: [Function: isBloom], isUserEthereumAddressInBloom: [Function: isUserEthereumAddressInBloom], isContractAddressInBloom: [Function: isContractAddressInBloom], isTopic: [Function: isTopic], isTopicInBloom: [Function: isTopicInBloom], isInBloom: [Function: isInBloom], compareBlockNumbers: [Function: compareBlockNumbers], toNumber: [Function: toNumber] }, Method: [Function: Method] }, clearSubscriptions: [Function (anonymous)], options: { address: [Getter/Setter], jsonInterface: [Getter/Setter] }, handleRevert: [Getter/Setter], defaultCommon: [Getter/Setter], defaultHardfork: [Getter/Setter], defaultChain: [Getter/Setter], transactionPollingTimeout: [Getter/Setter], transactionPollingInterval: [Getter/Setter], transactionConfirmationBlocks: [Getter/Setter], transactionBlockTimeout: [Getter/Setter], blockHeaderTimeout: [Getter/Setter], defaultAccount: [Getter/Setter], defaultBlock: [Getter/Setter], methods: { SetNFTMultiplierToken: [Function: bound _createTxObject], '0xde4ef212': [Function: bound _createTxObject], 'SetNFTMultiplierToken(address)': [Function: bound _createTxObject], SetRewardToken: [Function: bound _createTxObject], '0x6f8c206c': [Function: bound _createTxObject], 'SetRewardToken(address)': [Function: bound _createTxObject], SetStakeLPToken: [Function: bound _createTxObject], '0x07568441': [Function: bound _createTxObject], 'SetStakeLPToken(address)': [Function: bound _createTxObject], balanceOf: [Function: bound _createTxObject], '0x70a08231': [Function: bound _createTxObject], 'balanceOf(address)': [Function: bound _createTxObject], computeContribution: [Function: bound _createTxObject], '0x1b510c14': [Function: bound _createTxObject], 'computeContribution(uint256,uint256)': [Function: bound _createTxObject], computeMultiplier: [Function: bound _createTxObject], '0x62dfa108': [Function: bound _createTxObject], 'computeMultiplier(address)': [Function: bound _createTxObject], contributionOf: [Function: bound _createTxObject], '0xd7805ece': [Function: bound _createTxObject], 'contributionOf(address)': [Function: bound _createTxObject], duration: [Function: bound _createTxObject], '0x0fb5a6b4': [Function: bound _createTxObject], 'duration()': [Function: bound _createTxObject], earned: [Function: bound _createTxObject], '0x008cc262': [Function: bound _createTxObject], 'earned(address)': [Function: bound _createTxObject], exit: [Function: bound _createTxObject], '0xe9fad8ee': [Function: bound _createTxObject], 'exit()': [Function: bound _createTxObject], getReward: [Function: bound _createTxObject], '0x3d18b912': [Function: bound _createTxObject], 'getReward()': [Function: bound _createTxObject], lastTimeRewardApplicable: [Function: bound _createTxObject], '0x80faa57d': [Function: bound _createTxObject], 'lastTimeRewardApplicable()': [Function: bound _createTxObject], lastUpdateTime: [Function: bound _createTxObject], '0xc8f33c91': [Function: bound _createTxObject], 'lastUpdateTime()': [Function: bound _createTxObject], multiplierOf: [Function: bound _createTxObject], '0x8e4a5248': [Function: bound _createTxObject], 'multiplierOf(address)': [Function: bound _createTxObject], notifyRewardAmount: [Function: bound _createTxObject], '0x3c6b16ab': [Function: bound _createTxObject], 'notifyRewardAmount(uint256)': [Function: bound _createTxObject], owner: [Function: bound _createTxObject], '0x8da5cb5b': [Function: bound _createTxObject], 'owner()': [Function: bound _createTxObject], periodFinish: [Function: bound _createTxObject], '0xebe2b12b': [Function: bound _createTxObject], 'periodFinish()': [Function: bound _createTxObject], renounceOwnership: [Function: bound _createTxObject], '0x715018a6': [Function: bound _createTxObject], 'renounceOwnership()': [Function: bound _createTxObject], rewardDistribution: [Function: bound _createTxObject], '0x101114cf': [Function: bound _createTxObject], 'rewardDistribution()': [Function: bound _createTxObject], rewardPerToken: [Function: bound _createTxObject], '0xcd3daf9d': [Function: bound _createTxObject], 'rewardPerToken()': [Function: bound _createTxObject], rewardPerTokenStored: [Function: bound _createTxObject], '0xdf136d65': [Function: bound _createTxObject], 'rewardPerTokenStored()': [Function: bound _createTxObject], rewardRate: [Function: bound _createTxObject], '0x7b0a47ee': [Function: bound _createTxObject], 'rewardRate()': [Function: bound _createTxObject], rewards: [Function: bound _createTxObject], '0x0700037d': [Function: bound _createTxObject], 'rewards(address)': [Function: bound _createTxObject], setRewardDistribution: [Function: bound _createTxObject], '0x0d68b761': [Function: bound _createTxObject], 'setRewardDistribution(address)': [Function: bound _createTxObject], stake: [Function: bound _createTxObject], '0xa694fc3a': [Function: bound _createTxObject], 'stake(uint256)': [Function: bound _createTxObject], totalContributions: [Function: bound _createTxObject], '0x37c08923': [Function: bound _createTxObject], 'totalContributions()': [Function: bound _createTxObject], totalSupply: [Function: bound _createTxObject], '0x18160ddd': [Function: bound _createTxObject], 'totalSupply()': [Function: bound _createTxObject], transferOwnership: [Function: bound _createTxObject], '0xf2fde38b': [Function: bound _createTxObject], 'transferOwnership(address)': [Function: bound _createTxObject], userRewardPerTokenPaid: [Function: bound _createTxObject], '0x8b876347': [Function: bound _createTxObject], 'userRewardPerTokenPaid(address)': [Function: bound _createTxObject], withdraw: [Function: bound _createTxObject], '0x2e1a7d4d': [Function: bound _createTxObject], 'withdraw(uint256)': [Function: bound _createTxObject] }, events: { MultiplierComputed: [Function: bound ], '0xe483f88a85578f0fc325c6aabb8f618d2d0f712d8e98493e8cc1fba91d61b778': [Function: bound ], 'MultiplierComputed(address,uint256,uint256)': [Function: bound ], OwnershipTransferred: [Function: bound ], '0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0': [Function: bound ], 'OwnershipTransferred(address,address)': [Function: bound ], RewardAdded: [Function: bound ], '0xde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d': [Function: bound ], 'RewardAdded(uint256)': [Function: bound ], RewardPaid: [Function: bound ], '0xe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486': [Function: bound ], 'RewardPaid(address,uint256)': [Function: bound ], Staked: [Function: bound ], '0x9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d': [Function: bound ], 'Staked(address,uint256)': [Function: bound ], Withdrawn: [Function: bound ], '0x7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5': [Function: bound ], 'Withdrawn(address,uint256)': [Function: bound ], allEvents: [Function: bound ] }, _address: '0x4AB071C42C28c4858C4BAc171F06b13586b20F30', _jsonInterface: [ { inputs: [Array], stateMutability: 'nonpayable', type: 'constructor', constant: undefined, payable: undefined }, { anonymous: false, inputs: [Array], name: 'MultiplierComputed', type: 'event', constant: undefined, payable: undefined, signature: '0xe483f88a85578f0fc325c6aabb8f618d2d0f712d8e98493e8cc1fba91d61b778' }, { anonymous: false, inputs: [Array], name: 'OwnershipTransferred', type: 'event', constant: undefined, payable: undefined, signature: '0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0' }, { anonymous: false, inputs: [Array], name: 'RewardAdded', type: 'event', constant: undefined, payable: undefined, signature: '0xde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d' }, { anonymous: false, inputs: [Array], name: 'RewardPaid', type: 'event', constant: undefined, payable: undefined, signature: '0xe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486' }, { anonymous: false, inputs: [Array], name: 'Staked', type: 'event', constant: undefined, payable: undefined, signature: '0x9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d' }, { anonymous: false, inputs: [Array], name: 'Withdrawn', type: 'event', constant: undefined, payable: undefined, signature: '0x7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5' }, { inputs: [Array], name: 'SetNFTMultiplierToken', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0xde4ef212' }, { inputs: [Array], name: 'SetRewardToken', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x6f8c206c' }, { inputs: [Array], name: 'SetStakeLPToken', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x07568441' }, { inputs: [Array], name: 'balanceOf', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x70a08231' }, { inputs: [Array], name: 'computeContribution', outputs: [Array], stateMutability: 'pure', type: 'function', constant: true, payable: undefined, signature: '0x1b510c14' }, { inputs: [Array], name: 'computeMultiplier', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x62dfa108' }, { inputs: [Array], name: 'contributionOf', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0xd7805ece' }, { inputs: [], name: 'duration', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x0fb5a6b4' }, { inputs: [Array], name: 'earned', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x008cc262' }, { inputs: [], name: 'exit', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0xe9fad8ee' }, { inputs: [], name: 'getReward', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x3d18b912' }, { inputs: [], name: 'lastTimeRewardApplicable', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x80faa57d' }, { inputs: [], name: 'lastUpdateTime', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0xc8f33c91' }, { inputs: [Array], name: 'multiplierOf', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x8e4a5248' }, { inputs: [Array], name: 'notifyRewardAmount', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x3c6b16ab' }, { inputs: [], name: 'owner', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x8da5cb5b' }, { inputs: [], name: 'periodFinish', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0xebe2b12b' }, { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x715018a6' }, { inputs: [], name: 'rewardDistribution', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x101114cf' }, { inputs: [], name: 'rewardPerToken', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0xcd3daf9d' }, { inputs: [], name: 'rewardPerTokenStored', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0xdf136d65' }, { inputs: [], name: 'rewardRate', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x7b0a47ee' }, { inputs: [Array], name: 'rewards', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x0700037d' }, { inputs: [Array], name: 'setRewardDistribution', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x0d68b761' }, { inputs: [Array], name: 'stake', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0xa694fc3a' }, { inputs: [], name: 'totalContributions', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x37c08923' }, { inputs: [], name: 'totalSupply', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x18160ddd' }, { inputs: [Array], name: 'transferOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0xf2fde38b' }, { inputs: [Array], name: 'userRewardPerTokenPaid', outputs: [Array], stateMutability: 'view', type: 'function', constant: true, payable: undefined, signature: '0x8b876347' }, { inputs: [Array], name: 'withdraw', outputs: [], stateMutability: 'nonpayable', type: 'function', constant: undefined, payable: undefined, signature: '0x2e1a7d4d' } ]}C:\Users\erdtm\Documents\Blockchain Projects\mSandMaticStakingAutomation\contract-interact.js:12mSandMaticContract.balanceOf('0x7e5475290Df8E66234A541483453B5503551C780') ^TypeError: mSandMaticContract.balanceOf is not a function at Object.<anonymous> (C:\Users\erdtm\Documents\Blockchain Projects\mSandMaticStakingAutomation\contract-interact.js:12:20) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47
Original Link: https://dev.to/christianerdtmann/interact-with-existing-smart-contract-41e3
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To