Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Dec 21, 2023
1 parent 9434ccf commit 7283dbc
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/contract/precompile_contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,38 @@ struct Header {
```
</details>

#### Example

<details><summary>Click here to view example</summary>

```solidity
contract GetCkbHeader {
event GetHeaderEvent(CKBHeader);
event NotGetHeaderEvent();
int8 ret;
function getHeader(bytes32 blockHash) public returns (CKBHeader memory) {
address get_header_addr = address(0x0102);
(bool isSuccess, bytes memory res) = get_header_addr.staticcall(
abi.encode(blockHash)
);
CKBHeader memory header;
if (isSuccess) {
header = abi.decode(res, (CKBHeader));
emit GetHeaderEvent(header);
} else {
emit NotGetHeaderEvent();
}
return header;
}
}
```

</details>

### GetCell

| ADDRESS | MINIMUM GAS | INPUT | OUTPUT |
Expand Down Expand Up @@ -175,6 +207,38 @@ struct CellOutput {
```
</details>

#### Example

<details><summary>Click here to view example</summary>

```solidity
contract GetCkbCell {
event GetCellEvent(OutPoint);
event NotGetCellEvent();
int8 ret;
function getCell(bytes32 blockHash) public returns (CellInfo memory) {
address get_cell_addr = address(0x0103);
(bool isSuccess, bytes memory res) = get_cell_addr.staticcall(
abi.encode(outPoint)
);
CellInfo memory cell;
if (isSuccess) {
cell = abi.decode(res, (CellInfo));
emit GetCellEvent(cell);
} else {
emit NotGetCellEvent();
}
return cell;
}
}
```

</details>

### CallCkbVm

| ADDRESS | MINIMUM GAS | INPUT | OUTPUT |
Expand Down

0 comments on commit 7283dbc

Please sign in to comment.