混音"Error from IDE : Invalid account selected"错误



我是新混音和固体,不明白为什么我收到错误信息">IDE错误:选择的无效帐户"。下面一行执行成功:

await contract.methods.SetMaxSupply("600").send({from: accounts[0]});

下面一行导致上面提到的错误消息:

let supply = await contract.methods.current_supply().call()

可靠代码:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;


import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract Test is Ownable {

uint public max_supply; 

function SetMaxSupply(uint amount) public onlyOwner { 
max_supply = amount;
}

function current_supply() public view returns(uint) {
return max_supply * 3;
}

}

Remix JS Script:

// Right click on the script name and hit "Run" to execute
(async () => {
try {
console.log('Running deployWithWeb3 script...')

// replace with contract address
const contractAddress = '0xd9145CCE52D386f254917e481eB44e9943F39138'

const contractName = 'Test' // Change this for other contract

// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/StackOverflow/artifacts/${contractName}.json` // Change this for different path

const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const abi = metadata.abi

// instantiate a new web3 Contract object
let contract = new web3.eth.Contract(abi, contractAddress)

const accounts = await web3.eth.getAccounts()

await contract.methods.SetMaxSupply("600").send({from: accounts[0]});

let supply = await contract.methods.current_supply().call()

console.log(supply)

} catch (e) {
console.log(e.message)
}
})()

尝试更改帐户Deploy &运行事务

最新更新