Skip to content

Updating Auction Dapp to Web3 1.2.9 (added Bee with Webpack4 and Babel7) #1123

Open
@mshearer0

Description

@mshearer0

I had to make a few changes to Auction Dapp to run with current Web3:

Web3 1.2.9
Node 16.14.0
NPM 8.5.2

  1. Update main.js as
	if(typeof web3 !== 'undefined') {    
            if (window.ethereum) {
                web3 = new Web3_1(window.ethereum)
            }
            this.$auctionRepoInstance.setWeb3(web3)
            this.$deedRepoInstance.setWeb3(web3)    

            store.setMetamaskInstalled()

            web3.eth.net.getId().then(netId => { store.setNetworkId(netId) })
  1. Update App.vue to use web3.utils.BN:
// get random deedid
            this.deed.deedId = new web3.utils.BN(`${this.$root.$data.globalState.getRandomInt(123456789,999999999)}${this.$roo
t.$data.globalState.getRandomInt(123456789,999999999)}`)
  1. In Models add 'new' to initialise contract:
this.contractInstance = new this.web3.eth.Contract(Config.DEEDREPOSITORY_ABI,Config.DEEDREPOSITORY_ADDRESS)
  1. In Models update all the contract fn calls to either .send (if write) or .call (if read only) in this format:
this.contractInstance.methods.registerDeed(deedId, deedURI).send({from: this.account, gas: this.gas }, function(err,
 transaction) {    
  1. In Models update all the watchers as:
    async watchIfCreated(cb) {
        const currentBlock = await this.getCurrentBlock()
        this.contractInstance.events.DeedRegistered({
            filter: {}, 
            fromBlock: currentBlock - 1
            },  cb)
    }
  1. Update .fromWei() to utils.fromWei()

  2. If using Ropsten config.js should be of format:

JSONRPC_ENDPOINT: 'https://ropsten.infura.io/v3/_your_id',
JSONRPC_WS_ENDPOINT: 'wss://ropsten.infura.io/ws/v3/_your_id',

Note Ganache-ui doesn't support websockets so cant be used for testing. Ganache-cli does.

  1. In backend the truffle test needed to be updated:
it("It should register a deed with id: 123456789", async () => {
        await instance.registerDeed(123456789,"test");
        let ownerOfDeed = await instance.exists(123456789);
        assert.equal(ownerOfDeed.valueOf(), true , `Result should be true`);
    });

Make sure DEEDREPOSITORY_ADDRESS and AUCTIONREPOSITORY_ADDRESS are the addresses of your contracts after deployment and that JSON files from backend/build/contracts match.

Swarm bee needs to be updated so have commented these lines out for now, leaving

let imageUrl = "";

Happy to submit pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions