Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write request to BSC smart contract method. #328

Open
cjmling opened this issue Feb 24, 2022 · 1 comment
Open

How to write request to BSC smart contract method. #328

cjmling opened this issue Feb 24, 2022 · 1 comment

Comments

@cjmling
Copy link
Owner

cjmling commented Feb 24, 2022

  1. Download the contract abi file save as json. For example https://bscscan.com/address/0x8e33802adb469571e63a9677b453cfcd45852fe3#code

it will look something like this

[
  {
    "inputs": [
      { "internalType": "address", "name": "_strategy", "type": "address" }
    ],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "anonymous": false,
@cjmling
Copy link
Owner Author

cjmling commented Feb 24, 2022

  1. Start contract instance

while web3 is

import Web3 from 'web3'
declare const window: any

const provider =
  process.browser && window !== undefined && window.ethereum !== undefined
    ? window.ethereum
    : 'https://bsc-dataseed.binance.org/'

const web3: any = new Web3(provider)

abi is the json file

import abiFile from '../../data/abis/filename.json'

address is the contract address , which in this case 0x8e33802adb469571e63a9677b453cfcd45852fe3

new web3.eth.Contract(abi, address);

  1. Call the method you want.

const discountBP = await contract.methods.getDiscountBP(account).call()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant