Search code examples
blockchainsoliditytruffleganachedecentralized-applications

Is there a way to access the account used for the deployment process in Ganache?


I am building a decentralized application and the embedded smart contract contains a function, which can be called only by the owner of the smart contract (i.e. the account that initiated the deployment process). I am using Ganache, which comes with 10 predefined accounts. From what I know, the address used for deployment is the first one from that list of accounts, so I call that function with the first address returned by web3.eth.getAccounts() as argument. But there is a problem. When I change the account from Metamask, web3.eth.getAccounts() changes its value and the first address is the one from Metamask. How can I get the account used for deployment, without using web3.eth.getAccounts()?


Solution

  • just copy and paste the address' in from the one you want in ganache. the top listed address where the contracts were deployed

    web3.eth.sendTransaction({ to: "0xc25903033606D6D9FeE655E58F024b152B1734C1", from: '0x2fbFa394f462755a1c5c68eB4cee47b243046afc'})