Contract

var Web3= require("web3")
const path = require('path');
const fs = require('fs');
var contract = require("truffle-contract");
App = {
    web3Provider: null,
    contracts: {},

    init: async function() {


        return await App.initWeb3();
    },

    initWeb3: async function() {

        App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
        web3 = new Web3(App.web3Provider);

        return App.initContract();
    },

    initContract: function() {

        const contractPath = path.resolve(__dirname, './build/contracts/Adoption.json');


            // Get the necessary contract artifact file and instantiate it with truffle-contract
            const {abi,bytecode} = require(contractPath);

        const myContract = new web3.eth.Contract(abi,'0xDB311d10bA37e994d9b12a9d2f381Bc220aA6fdF',
            {
                from: '0xE8DFF694ce99856da7d88e5569ebd02F97931816', // default from address
            });

            // Set the provider for our contract
        myContract.setProvider(App.web3Provider);


        function getSomething() {
            return "something";
        }

        async function testAsync() {
            return Promise.resolve("hello async");
        }

        async function test() {
            const v1 = await myContract.methods.adopt(1).send({from: '0xE8DFF694ce99856da7d88e5569ebd02F97931816',
                gas: "220000"}, (error, transactionHash) => {
                console.log(transactionHash)
            });
            myContract.methods.getAdopters().call().then(console.log);
        }
        test()



    }



};
App.init();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值