@@ -31,10 +31,8 @@ You should use foundry to [create a new project](https://book.getfoundry.sh/proj
3131forge install https://github.com/webisopen/ovm-contracts
3232```
3333
34-
35342 . Otherwise you can use NPM to install the dependencies, there are two packages required:
3635
37-
3836``` bash
3937 npm i @webisopen/ovm-contracts @openzeppelin/contracts
4038```
@@ -51,21 +49,24 @@ You may refer to the [OVM Cal PI](https://github.com/webisopen/ovm-cal-pi) repos
5149
5250#### Initialization
5351
54- The constructor initializes the smart contract with the specification of the task to be executed.
52+ This contract inherits from ` OVMClient ` and ` OwnableUpgradeable ` .
53+ In the `` initialize `` method, it initializes the smart contract with the specification of the task to be executed.
5554For more details, refer to the [ OVM Contract Specification] ( ./specification ) .
5655
57- Additionally, ` admin ` address is also defined in the constructor for collecting royalty fees .
56+ Additionally, ` owner ` address is defined to collect royalty fees escrowed in the contract .
5857
5958``` solidity
60- constructor(
61- address OVMTaskAddress,
62- address admin
63- ) OVMClient(OVMTaskAddress, admin) {
59+ contract Pi is OVMClient, OwnableUpgradeable {
60+ // ...
61+ function initialize(address owner) external initializer {
62+ __Ownable_init(owner);
63+
64+ // set specification
6465 Specification memory spec;
6566 spec.name = "ovm-cal-pi";
6667 spec.version = "1.0.0";
6768 spec.description = "Calculate PI";
68- spec.repository = "https://github.com/webisopen/ovm-cal- pi";
69+ spec.repository = "https://github.com/webisopen/ovm-pi";
6970 spec.repoTag = "9231c80a6cba45c8ff9a1d3ba19e8596407e8850";
7071 spec.license = "WTFPL";
7172 spec.requirement = Requirement({
@@ -76,14 +77,16 @@ Additionally, `admin` address is also defined in the constructor for collecting
7677 gpu: 0,
7778 gpuModel: GPUModel.T4
7879 });
79- spec
80- .apiABIs = '[{"request": {"type":"function","name":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]';
80+ spec.apiABIs =
81+ '[{"request": {"type":"function","name":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]';
8182 spec.royalty = 5;
8283 spec.execMode = ExecMode.JIT;
83- spec.arch = Arch.ARM64 ;
84+ spec.arch = Arch.AMD64 ;
8485
8586 _updateSpecification(spec);
8687 }
88+ // ...
89+ }
8790```
8891
8992#### Send Request
@@ -141,6 +144,15 @@ The interface `function setResponse(bytes32 requestId, bytes calldata data)` mus
141144
142145Similarly, you need to decode the response here.
143146
147+ #### Collect Royalty
148+
149+ Royalty fees are escrowed in the contract, this function enables the owner to withdraw the fees.
150+ ``` solidity
151+ function withdraw() external onlyOwner {
152+ payable(owner()).transfer(address(this).balance);
153+ }
154+ ```
155+
144156## Conclusion
145157
146158In this guide, we demonstrated how to publish an OVM task by building a smart contract that specifies the computation to be executed, the environment in which it should run, and the requirements for the execution.
0 commit comments