uport-project / ethr-did

Create ethr DIDs
Apache License 2.0
259 stars 53 forks source link

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

Closed ErvinDimitri closed 3 years ago

ErvinDimitri commented 3 years ago

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

mirceanis commented 3 years ago

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.

ErvinDimitri commented 3 years ago

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 commented 3 years ago

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