Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ContractManagement.GetContractById Method

Maps the specified ID to the deployed contract.

Namespace: [Neo.SmartContract.Framework.Native](../../native.md)

Assembly: Neo.SmartContract.Framework

## Syntax

```c#
public ContractState GetContractById(int id);
```

Parameters:

- id: Contract ID. Negative numbers represent native contracts, while positive numbers represent normal contracts (non-native deployed contracts).

## Example

Contract:

```c#
public class Contract1 : SmartContract
{
public static string MyMethod(int id)
{
var contract = ContractManagement.GetContractById(id);
return contract.Manifest.Name;
}
}
```

Invoke from neo-cli:

```
invoke 0x425d355a8a62eebf961884c91c6567d3ff1ab0dc myMethod [{"type":"Integer","value":"-1"}]
```

Invoke from RPC:

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "invokefunction",
"params": [
"0x425d355a8a62eebf961884c91c6567d3ff1ab0dc",
"myMethod",
[
{
"type": "Integer",
"value": "-1"
}
]
]
}
```

Response body:

```json
[
{
"type":"ByteString",
"value":"Q29udHJhY3RNYW5hZ2VtZW50"
}
]
```

Response description:

According to the contract code, the contract name associated with the requested ID is returned here.

The string `Q29udHJhY3RNYW5hZ2VtZW50`, when decoded with base64, yields `ContractManagement`.

[Back](../ContractManagement.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# ContractManagement.GetContractById Method

Gets the hashes of all non-native deployed contracts.

Namespace: [Neo.SmartContract.Framework.Native](../../native.md)

Assembly: Neo.SmartContract.Framework

## Syntax

```c#
private IIterator GetContractHashes()
```

Return:

Iterator with hashes of all deployed contracts.

## Example

Contract:

```c#
public static Iterator<(int, UInt160)> MyMethod()
{
return ContractManagement.GetContractHashes();
}
```

Invoke from RPC:

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "invokefunction",
"params": [
"0xc04ff111aa88cc5239cf36360cb298a9a3eae586",
"myMethod",
[]
]
}
```

Response body:

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"script": "wh8MCG15TWV0aG9kDBSG5eqjqZiyDDY2zzlSzIiqEfFPwEFifVtS",
"state": "HALT",
"gasconsumed": "2950200",
"exception": null,
"notifications": [],
"stack": [
{
"type": "InteropInterface",
"interface": "IIterator",
"id": "0cd0591b-cf5a-4517-a060-779269f3577d"
}
],
"session": "4829327b-8c1d-439e-becc-1360453839f6"
}
}
```

Invoke again from RPC to get the specific value of the iterator. For more information, refer to the command [traverseiterator](../../../../rpc/latest-version/api/traverseiterator.md).

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "traverseiterator",
"params": [
"4829327b-8c1d-439e-becc-1360453839f6",
"0cd0591b-cf5a-4517-a060-779269f3577d",
10
]
}
```

Response body:

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"type": "Struct",
"value": [
{
"type": "ByteString",
"value": "AAAAAQ=="
},
{
"type": "ByteString",
"value": "3LAa/9NnZRzJhBiWv+5iilo1XUI="
}
]
},
{
"type": "Struct",
"value": [
{
"type": "ByteString",
"value": "AAAAAg=="
},
{
"type": "ByteString",
"value": "gwlF8xm/6snmJCfRzDiaIiu40pI="
}
]
},
{
"type": "Struct",
"value": [
{
"type": "ByteString",
"value": "AAAAAw=="
},
{
"type": "ByteString",
"value": "oDlHkjZPmX2hcY9E7b0Wdwwoxa8="
}
]
},
{
"type": "Struct",
"value": [
{
"type": "ByteString",
"value": "AAAABA=="
},
{
"type": "ByteString",
"value": "huXqo6mYsgw2Ns85UsyIqhHxT8A="
}
]
}
]
}
```

Response description:

Each element of the returned array is a contract message containing the contract ID and Hash.

Base64 string `AAAABA==` to hexadecimal string is `00000004`.

Base64 script hash `huXqo6mYsgw2Ns85UsyIqhHxT8A=` to script hash (little-endian) is `86e5eaa3a998b20c3636cf3952cc88aa11f14fc0`.

[Back](../ContractManagement.md)