【发布时间】:2019-06-09 14:35:46
【问题描述】:
我已将我的 ERC721 合约部署到 Rinkeby 测试网。合约已成功部署。我无法使用 MetaMask 调用事务。花了一整天的时间来解决这个问题。找到了一些答案,说明 localhosted 文件的问题或 web3.js 不适用于 MetaMask。
<script>
if (typeof web3 != 'undefined') {
web3 = new Web3(web3.currentProvider) // what Metamask injected
console.log("existing web3: provider " + typeof web3);
} else {
// Instantiate and set Ganache as your provider
web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/api-key"));
console.log("new provider " + web3);
web3.eth.defaultAccount = web3.eth.accounts[0]
}
// The interface definition for your smart contract (the ABI)
var StarNotary = web3.eth.contract(
[contract-abi]
)
const starNotary = StarNotary.at('0x7cfAD6E80D992599d989166aABf536b21215544C')
function claimStar() {
web3.eth.getAccounts(function(error, accounts) {
if (error) {
hotsnackbar(false, error);
return
}
未捕获的错误:地址无效 在你(web3.min.js:1) 在 inputTransactionFormatter (web3.min.js:1) 在 web3.min.js:1 在 Array.map() 在 i.formatInput (web3.min.js:1) 在 i.toPayload (web3.min.js:1) 在 _.e [作为 sendTransaction] (web3.min.js:1) 在 c.sendTransaction (web3.min.js:1) 在 index.html:589 在 web3.min.js:1
【问题讨论】:
-
你确定是
https://rinkeby.infura.io/v3/api-key? -
这是infura链接
-
试试这个链接:
https://rinkeby.infura.io/<your-key-here> -
是的,我也这样做了。我刚刚删除了此处发布的 api-key。