@@ -31,10 +31,8 @@ You should use foundry to [create a new project](https://book.getfoundry.sh/proj
31
31
forge install https://github.com/webisopen/ovm-contracts
32
32
```
33
33
34
-
35
34
2 . Otherwise you can use NPM to install the dependencies, there are two packages required:
36
35
37
-
38
36
``` bash
39
37
npm i @webisopen/ovm-contracts @openzeppelin/contracts
40
38
```
@@ -51,21 +49,24 @@ You may refer to the [OVM Cal PI](https://github.com/webisopen/ovm-cal-pi) repos
51
49
52
50
#### Initialization
53
51
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.
55
54
For more details, refer to the [ OVM Contract Specification] ( ./specification ) .
56
55
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 .
58
57
59
58
``` 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
64
65
Specification memory spec;
65
66
spec.name = "ovm-cal-pi";
66
67
spec.version = "1.0.0";
67
68
spec.description = "Calculate PI";
68
- spec.repository = "https://github.com/webisopen/ovm-cal- pi";
69
+ spec.repository = "https://github.com/webisopen/ovm-pi";
69
70
spec.repoTag = "9231c80a6cba45c8ff9a1d3ba19e8596407e8850";
70
71
spec.license = "WTFPL";
71
72
spec.requirement = Requirement({
@@ -76,14 +77,16 @@ Additionally, `admin` address is also defined in the constructor for collecting
76
77
gpu: 0,
77
78
gpuModel: GPUModel.T4
78
79
});
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"}}]';
81
82
spec.royalty = 5;
82
83
spec.execMode = ExecMode.JIT;
83
- spec.arch = Arch.ARM64 ;
84
+ spec.arch = Arch.AMD64 ;
84
85
85
86
_updateSpecification(spec);
86
87
}
88
+ // ...
89
+ }
87
90
```
88
91
89
92
#### Send Request
@@ -141,6 +144,15 @@ The interface `function setResponse(bytes32 requestId, bytes calldata data)` mus
141
144
142
145
Similarly, you need to decode the response here.
143
146
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
+
144
156
## Conclusion
145
157
146
158
In 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