SimpleConsumercontract accepts the
coinPricecoming in only from the
CoinOracleit was assigned when it got deployed. Additionally,
CoinOracleaccepts updates only if it is signed by the same Wallet that deployed it (
owner) and store it in the Web3 Actions Secrets (needed to sign transactions in interaction 5).
CoinOraclecontact must be deployed first, before the
SimpleCoinConsumercontract, preferably using a different Wallet. Make sure to pass the
CoinOracleaddress as the constructor parameter.
cdinto it to initialize your Web3 Actions using the
tenderly actions initcommand.
CONTRACT_ADDRESSvariable to the address of your deployed
getPrice. The result we get from the API will be the price in cents. We’ll send this data back to our smart contract.
compilerOptions. This will stop Typescript from frowning upon us for importing a JSON file as an ES module.
CoinOracleContract.jsonfile creates an
Interfaceinstance that Ethers uses to encode and decode data exchanged when interacting with smart contracts. We’re passing the
abipart of the entire JSON file.
Interfacewe just created (
decodeEventLog. We know that the first log entry (
logs) corresponds to the
RequestCoinPriceevent, 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
oracleContractfunction, and here’s the breakdown of steps.
ethers.getDefaultProviderto 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
Walletto 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:
Contractinstance by passing
contractInterfacefor encoding data we want to send to the network.
oracleWlletto sign the transaction.
receiveWeatherUpdateand sends the prediction our oracle has come up with. This bit issues a transaction to our smart contract.
RequestCoinPriceevent is fired by the
OracleContracton the Ropsten network. We want to do this only after the transaction has been mined.
YOUR_PROJECT_SLUGwith your Tenderly username and the slug of your project. You can copy those from the Dashboard URL:
CONTRACT_ADDRESSwith 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.
oracle.providerApiKeyand paste the API token as well as any other sensitive information you need.
OracleContractis designed to only accept updates that are signed by the address that deployed them.
w3_oracle.oracle_address_private_keyand paste the private key.
tenderly.yamlfile) and run the following command:
doSomethingSmartfunction of the
updatefunction of the