"How do you interact directly with an Ethereum smart contract?"
Step-by-step example below 👇
⚠️Ability to read code is required⚠️
#JeremyAnswers#solidity#blockend
There are a few ways to do this but I'll go over the one which doesn't require any setup.
Note: This method only works if the contract you want to interact with has verified it's source code on Etherscan.
Click on the "Contract" button to reveal the source code.
If you can't find the verified source code, this method isn't going to work.
You might find several different files, if this is the case you'll have to locate the "main" source file.
Look for a file that matches the name of the contract.
The file's class type should be "contract". It should not contain the words "abstract", "interface" or "library".
Copy the code in the "main" source file to a new file in Remix IDE.
Ensure the name of your file in Remix matches the file name in Etherscan.
Check to see if the "main" source file has any non-external dependencies, copy these over if so.
If you're not sure, just proceed. Remix IDE will tell you if you're missing a dependency when you try to compile.
In Remix IDE, click on the compile tab (3rd one from to top on the very left).
Make sure you have the right compiler version selected and hit "Compile".
If you get an error message like this, you've missed a dependency.
Go back to Etherscan, look for the file and copy the contents of that file over to a new file in Remix IDE.
Remember to match the name of your file in Remix with the one in Etherscan.
You should have successfully compiled the file by now.
(If you're following my example, ignore the warning)
If you're still getting errors, keep trying or call a friend who knows how to code to give you a hand.
Click on the "Deploy & Run Transactions" tab.
Under "Environment", click on "Injected Web3" and connect your wallet.
Ensure your wallet is connected to the correct network (for my example use Rinkeby).
If you don't have a wallet, set one up and get ETH from a Rinkeby faucet (Google for instructions).
Select the "main" source file in the "Contract" dropdown.
In this case Vendor.sol.
At the very bottom you'll see a box which has a button that says "At Address".
Paste the address of the contract in the box and hit "At Address".
Expand the contact which appeared under "Deployed Contracts".
You should see something like this 👇
Now you're ready to call the functions of the contract.
In order to know what each function does, you'll need to read it's code.
Example, let's use the "buyTokens" function.
In the code we can see that 100 tokens costs 1 ETH.
Let's say we want to buy 1 token, that will cost 0.01 ETH or 0.01x10^9 Gwei.
To send ETH to the contract (while calling the function), you will need to fill out the "Value" box.
Enter 10000000 and change the units to Gwei.
Hit "buyTokens".
Confirm your transaction in Metamask.
Tada 🎉
If you followed along and want to check your token balance, go here:
stimulating-chin.surge.sh/
If you scroll to the bottom you should be able to see a list of buy and sell transactions.
Want to get into Ethereum development?
I recommend going through the challenges at speedrunethereum.com!