[英]Deploying new contract to etherium network with web3.js
我已嘗試使用相關依賴項運行此代碼以獲取合約地址,但收到錯誤消息
No "from" address specified in neither the given options, nor the default options.
從瀏覽器。 此外,通過使用 metamask ropsten 測試網使用 Remix 工具進行部署時沒有錯誤。
onSubmit = async (event) => {
event.preventDefault();
this.setState({ loading: true, errorMessage: '' });
try {
const accounts = await web3.eth.getAccounts();
console.log(accounts)
await factory.methods
.createCampaign(this.state.minimumContribution)
.send({ from: accounts[0] })
Router.pushRoute('/');
} catch (err) {
this.setState({ errorMessage: err.message })
}
this.setState({ loading: false });
}
console.log(accounts)
是否打印任何內容?
如果沒有,請嘗試使用以下代碼設置 web3:
if (typeof web3 !== 'undefined') {
window.web3 = new Web3(web3.currentProvider);
web3.currentProvider.enable();
} else {
window.web3 = new Web3(new Web3.providers.HttpProvider("..."));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.