Created
November 28, 2018 09:21
-
-
Save sauravtom/59dc36fb669d87a5998230beb752c668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//link to smart contract https://ethfiddle.com/Q4mg9xHlzR | |
let address = "0x03b6b93cf23f04a32aa94fe1ef96cae383900ea7"; | |
let abi = [ | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "newMessage", | |
"type": "string" | |
} | |
], | |
"name": "update", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"name": "initMessage", | |
"type": "string" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "constructor" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "message", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "string" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
] | |
provider = ethers.getDefaultProvider('ropsten'); | |
wallet = ethers.Wallet.createRandom(); | |
contract = new ethers.Contract(address, abi, provider); | |
contractWithSigner = contract.connect(wallet); | |
await contractWithSigner.update('msgString'); |
You have to attach the provider to the wallet: wallet = wallet.connect(provider)
I think that should be the only change you need. You can also pass Wallet directly into the Contract constructor and skip the read-only contract if you don’t need it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 51
contractWithSigner.update('msgString');
results in the following errorethers.js:289 Uncaught (in promise) TypeError: Cannot read property 'getCode' of undefined TypeError: Cannot read property 'getCode' of undefined
link to smart contract