RequestCoinPrice
event.SimpleConsumer
contract accepts the coinPrice
coming in only from the CoinOracle
it was assigned when it got deployed. Additionally, CoinOracle
accepts updates only if it is signed by the same Wallet that deployed it (owner
).CoinOracle
and SimpleCoinConsumer
smart contracts.owner
) and store it in the Web3 Actions Secrets (needed to sign transactions in interaction 5).CoinOracle
and SimpleCoinConsumer
contracts are stored in the same file: CoinOracle.sol
. Check out the source code in our GitHub repo.CoinOracle
contact must be deployed first, before the SimpleCoinConsumer
contract, preferably using a different Wallet. Make sure to pass the CoinOracle
address as the constructor parameter.tdly-actions
and cd
into it to initialize your Web3 Actions using the tenderly actions init
command.CoinOracleContract.json
file to the actions
directory. You can find this JSON file in Remix or this GitHub repo.actions
directory (e.g. CoinOracleContract.json
).CONTRACT_ADDRESS
variable to the address of your deployed Oracle
:getPrice
. The result we get from the API will be the price in cents. Weโll send this data back to our smart contract.tsconfig.json
file, under compilerOptions
. This will stop Typescript from frowning upon us for importing a JSON file as an ES module.CoinOracleContract.json
file creates an Interface
instance that Ethers uses to encode and decode data exchanged when interacting with smart contracts. Weโre passing the abi
part of the entire JSON file.Interface
we just created (ifc
) to decodeEventLog
. We know that the first log entry (logs[0]
) corresponds to the RequestCoinPrice
event, so this is the one we want to decode. In more complex interactions, you may need to do this dynamically like we did here.owner
. This means we need to send transactions from the address that deployed it. The plumbing is done in the oracleContract
function, and hereโs the breakdown of steps.ethers.getDefaultProvider
to work with network 3
(Ropstenโs ID). Weโre also passing a second argument โ a configuration object which contains the API key. Consult ethers docs for more information on how to configure other providers and use alternatives like JsonRpcProvider
.Wallet
to ensure that each transaction originating from our oracle is signed and funded by the same address that deployed the contract. Since the Walletโs private key is sensitive information, weโre reading it from Secrets:await context.secrets.get("w3_oracle.oracle_address_private_key")
Contract
instance by passing CONTRACT_ADDRESS
.contractInterface
for encoding data we want to send to the network.oracleWllet
to sign the transaction.receiveWeatherUpdate
and sends the prediction our oracle has come up with. This bit issues a transaction to our smart contract.RequestCoinPrice
event is fired by the OracleContract
on the Ropsten network. We want to do this only after the transaction has been mined.YOUR_USERNAME
and YOUR_PROJECT_SLUG
with your Tenderly username and the slug of your project. You can copy those from the Dashboard URL: https://dashboard.tenderly.co/{YOUR_USERNAME}/{YOUR_PROJECT_SLUG}/transactions
CONTRACT_ADDRESS
with the address of your deployed Oracle Contract:OracleContract
, we need a way to access the contract. You can choose any provider service (Infura, QuickNode, Alchemy, Etherscan, etc). Check Ethersโ Default Provider docs to find out whatโs needed to establish the access.console.log
the values, they will remain hidden.oracle.providerApiKey
and paste the API token as well as any other sensitive information you need.OracleContract
is designed to only accept updates that are signed by the address that deployed them.w3_oracle.oracle_address_private_key
and paste the private key.tenderly.yaml
file) and run the following command:doSomethingSmart
function of the SimpleCoinConsumer
contract.update
function of the OracleContract
contract. ๐