-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add example contract call * add deps resolutions to example * use ethers v6
- Loading branch information
1 parent
e7f4801
commit 310c6f4
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "ValueChanged", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "retrieve", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "store", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require('dotenv').config(); | ||
|
||
const { ethers, version } = require('ethers'); | ||
const BoxAbi = require('./box.json'); | ||
const { Defender } = require('@openzeppelin/defender-sdk'); | ||
|
||
function sleep(ms) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} | ||
|
||
async function main() { | ||
const creds = { | ||
relayerApiKey: process.env.RELAYER_API_KEY, | ||
relayerApiSecret: process.env.RELAYER_API_SECRET, | ||
}; | ||
const validUntil = new Date(Date.now() + 120 * 1000).toISOString(); | ||
|
||
const client = new Defender(creds); | ||
console.log('using ethers version ', version); | ||
|
||
const provider = client.relaySigner.getProvider({ ethersVersion: 'v6' }); | ||
const signer = await client.relaySigner.getSigner(provider, { speed: 'fast', validUntil, ethersVersion: 'v6' }); | ||
|
||
const contractAddress = '0x1B9ec5Cc45977927fe6707f2A02F51e1415f2052'; | ||
const contract = new ethers.Contract(contractAddress, BoxAbi, signer); | ||
|
||
console.log(`Calling store function`); | ||
const result = await contract.store('10'); | ||
|
||
console.log(`Transaction sent:`, result.hash); | ||
console.log(`Status:`, result.status); | ||
|
||
// polls until the transaction is mined. | ||
let recipt = null; | ||
while (recipt == null) { | ||
recipt = await provider.getTransactionReceipt(result.hash); | ||
console.log('sleep 1s before requesting again'); | ||
await sleep(1000); | ||
} | ||
console.log(recipt); | ||
} | ||
|
||
if (require.main === module) { | ||
main().catch(console.error); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@openzeppelin/defender-sdk-example-relayer-contract-function", | ||
"version": "1.14.1", | ||
"private": true, | ||
"main": "index.js", | ||
"author": "OpenZeppelin Defender <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"@openzeppelin/defender-sdk": "1.14.1", | ||
"dotenv": "^16.3.1", | ||
"ethers": "^6.9.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.