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();
Contract
最新推荐文章于 2022-11-05 23:45:58 发布