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

Getting error: -32000 - 'exceeds block gas limit' or 'transaction underpriced' #76

Closed
ErvinDimitri opened this issue Jun 30, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@ErvinDimitri
Copy link

ErvinDimitri commented Jun 30, 2021

Current Behavior

I am trying to run the following code on bsc testnet (already deployed the smart contract on bsc testnet)
I already ran in Ropsten Network and had no issues

On the following code, I pretend to set an attribute and I am getting the following error: { code: -32000, message: 'transaction underpriced' }
So i decided to add gasPrice as a parameter on setAttribute() function, but now I am getting another error: { code: -32000, message: 'exceeds block gas limit' }

Expected Behavior

Should just return the Tx hash

Failure Information

when i decrease the gasPrice, i receive this message { code: -32000, message: 'transaction underpriced' }
when i increase the gasPrice, i receive this message: { code: -32000, message: 'exceeds block gas limit' }

Steps to Reproduce

Running the following code:

const EthrDID = require('ethr-did').EthrDID
const HDWalletProvider = require("@truffle/hdwallet-provider")
  const mnemonic = "**** MNEMONIC ***".toString().trim()
const rpcLink = "https://data-seed-prebsc-1-s3.binance.org:8545/"
const chainId = 97
let provider = new HDWalletProvider(mnemonic, rpcLink, 0)
let Web3Provider = require ('@ethersproject/providers').Web3Provider

const bscAddr='0xA2D2Cb7Bb660E81032Db2a745986D3eDDaB34341'  // Smart contract address on bsc testnet
pubkey = 'PUBLIC KEY'
identif='did:ethr:0x2: PUBLIC KEY'

const main = async () => {
    
    let prov = await new Web3Provider(provider)
    const ethrDid = await new EthrDID({identifier: identif, provider: prov, signer: pubkey, registry:bscAddr, chainNameOrId:chainId, gasLimit: gasPrice})
    // let gasPrice = parseInt(29882814*1.04)  
    let response = ethrDid.setAttribute('drivL','142536',1629981511) 
        .then( (info) => console.log(response))
        .catch( (error) => console.log(error)
        )    
        
    provider.engine.stop()
}

main()

Environment Details

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Node version 14.17.1

@ErvinDimitri ErvinDimitri added the bug Something isn't working label Jun 30, 2021
@mirceanis
Copy link
Contributor

mirceanis commented Jul 1, 2021

I think there is a mixup of gasPrice and gasLimit in your code.
Please try removing any gasLimit or gasPrice from the constructor arguments and supplying them as txOptions to the setAttribute method:

pubkey = 'PUBLIC KEY'
identif=pubkey // when you use chainNameOrId, the DID string gets constructed automatically

const main = async () => {
    let prov = await new Web3Provider(provider)
    const ethrDid = await new EthrDID({identifier: identif, provider: prov, registry:bscAddr, chainNameOrId:chainId})
    let gasPrice = (await prov.getGasPrice()).toNumber() * 2
    let gasLimit = 10000000 // the BSC testnet block limit seems to be 30 million
    let response = ethrDid.setAttribute('drivL','142536',1629981511, null, {gasPrice, gasLimit}) 
        .then( (info) => console.log(response))
        .catch( (error) => console.log(error)
        )
    provider.engine.stop()
}

main()

Note
Please avoid posting personally identifiable information on-chain as this can have serious privacy implications.
When you call setAttribute, the attribute information remains public for as long as the blockchain is maintained, even if you later call revokeAttribute.

@mirceanis mirceanis self-assigned this Jul 1, 2021
@ErvinDimitri
Copy link
Author

ErvinDimitri commented Jul 1, 2021

It's working. Thank you very much!!!

I have a question about posting personal information on-chain:

If the data is encrypted (using a password defined by user) and store on IPFS and then post only the hash on-chain (or encrypt the IPFS's hash too and post on-chain)
Is this strategy efficient and secure?

@mirceanis
Copy link
Contributor

Glad to hear it works,and yes, that sounds like a reasonable strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants