sui_getObject
Retrieves comprehensive information about an object on the Sui blockchain, including its data, ownership, version, and type information.
Overview​
The sui_getObject
method is fundamental to interacting with Sui's object-centric architecture. Every piece of data on Sui is represented as an object with a unique identifier, and this method allows you to query any object's current state, ownership information, and associated metadata.
Parameters​
Parameter | Type | Required | Description |
---|---|---|---|
objectId | string | Yes | The unique identifier of the object (64-character hex string with 0x prefix) |
options | object | No | Options for controlling the response content |
Options Object​
Field | Type | Default | Description |
---|---|---|---|
showType | boolean | false | Include the object's Move type information |
showOwner | boolean | false | Include object ownership details |
showPreviousTransaction | boolean | false | Include the previous transaction digest |
showDisplay | boolean | false | Include display metadata if available |
showContent | boolean | false | Include the object's content fields |
showBcs | boolean | false | Include BCS-encoded object data |
showStorageRebate | boolean | false | Include storage rebate information |
Returns​
Returns an object containing the requested information about the Sui object.
Field | Type | Description |
---|---|---|
data | object | The object's data including content and metadata |
error | object | Error information if the object doesn't exist |
Object Data Structure​
Field | Type | Description |
---|---|---|
objectId | string | Unique identifier of the object |
version | string | Current version/sequence number |
digest | string | Object content digest |
type | string | Move type of the object (if requested) |
owner | object | Ownership information (if requested) |
previousTransaction | string | Previous transaction digest (if requested) |
storageRebate | string | Storage rebate amount (if requested) |
display | object | Display metadata (if requested) |
content | object | Object's fields and values (if requested) |
bcs | object | BCS-encoded data (if requested) |
Code Examples​
- cURL
- JavaScript
- Python
curl -X POST https://sui-mainnet.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "sui_getObject",
"params": [
"0x5d3c87e88bc566e3f10c66e0275a366001ffa8b86142adc78c744de6afffeb34",
{
"showType": true,
"showOwner": true,
"showPreviousTransaction": true,
"showDisplay": false,
"showContent": true,
"showBcs": false,
"showStorageRebate": true
}
],
"id": 1
}'
const response = await fetch('https://sui-mainnet.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'sui_getObject',
params: [
'0x5d3c87e88bc566e3f10c66e0275a366001ffa8b86142adc78c744de6afffeb34',
{
showType: true,
showOwner: true,
showPreviousTransaction: true,
showContent: true,
showStorageRebate: true
}
],
id: 1
})
});
const data = await response.json();
if (data.result?.data) {
console.log('Object ID:', data.result.data.objectId);
console.log('Version:', data.result.data.version);
console.log('Type:', data.result.data.type);
console.log('Owner:', data.result.data.owner);
console.log('Content:', data.result.data.content);
} else if (data.result?.error) {
console.error('Object not found:', data.result.error);
}
import requests
import json
url = 'https://sui-mainnet.dwellir.com/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
payload = {
"jsonrpc": "2.0",
"method": "sui_getObject",
"params": [
"0x5d3c87e88bc566e3f10c66e0275a366001ffa8b86142adc78c744de6afffeb34",
{
"showType": True,
"showOwner": True,
"showPreviousTransaction": True,
"showContent": True,
"showStorageRebate": True
}
],
"id": 1
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
result = response.json()
if 'data' in result.get('result', {}):
object_data = result['result']['data']
print(f"Object ID: {object_data['objectId']}")
print(f"Version: {object_data['version']}")
print(f"Type: {object_data.get('type', 'N/A')}")
print(f"Owner: {object_data.get('owner', 'N/A')}")
elif 'error' in result.get('result', {}):
print(f"Error: {result['result']['error']}")
Response Example​
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"data": {
"objectId": "0x5d3c87e88bc566e3f10c66e0275a366001ffa8b86142adc78c744de6afffeb34",
"version": "31823924",
"digest": "HpSeCiMLG53N9FcHDrRTxwGhc4RVJa1seZhXYJ7KFpJe",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"owner": {
"AddressOwner": "0xd77955e670601c2c2e6e8637e383695c166aac0a86b741c266bdfb23c2e3369f"
},
"previousTransaction": "C2QKmxrYPNBJjNmLtZrzFt9tVfq7wo2JZBmc5nQKYFdt",
"storageRebate": "988000",
"content": {
"dataType": "moveObject",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"hasPublicTransfer": true,
"fields": {
"balance": "1000000000",
"id": {
"id": "0x5d3c87e88bc566e3f10c66e0275a366001ffa8b86142adc78c744de6afffeb34"
}
}
}
}
}
}
Common Use Cases​
1. Querying Coin Objects​
// Get SUI coin object with balance
const coinObject = await provider.getObject({
id: coinObjectId,
options: {
showType: true,
showContent: true,
showOwner: true
}
});
const balance = coinObject.data?.content?.fields?.balance;
console.log(`Coin balance: ${balance}`);
2. Retrieving NFT Metadata​
// Get NFT with display information
const nftObject = await provider.getObject({
id: nftObjectId,
options: {
showDisplay: true,
showContent: true,
showOwner: true
}
});
const display = nftObject.data?.display?.data;
console.log(`NFT Name: ${display?.name}`);
console.log(`Image URL: ${display?.image_url}`);
3. Checking Object Ownership​
// Verify object ownership
const object = await provider.getObject({
id: objectId,
options: { showOwner: true }
});
const owner = object.data?.owner;
if (owner?.AddressOwner === userAddress) {
console.log('User owns this object');
} else if (owner?.Shared) {
console.log('This is a shared object');
} else if (owner?.Immutable) {
console.log('This is an immutable object');
}
Object Ownership Types​
Sui supports different ownership models that affect how objects can be accessed and modified:
Address-Owned Objects​
- Owner: Single address
- Access: Only the owner can modify
- Consensus: Fast-path execution without full consensus
Shared Objects​
- Owner: Accessible by anyone
- Access: Multiple transactions can access simultaneously
- Consensus: Requires full consensus
Immutable Objects​
- Owner: No owner (read-only)
- Access: Anyone can read, no one can modify
- Consensus: No consensus needed for reads
Object-Owned Objects​
- Owner: Another object
- Access: Through parent object transactions
- Consensus: Depends on parent object's ownership
Best Practices​
Optimize Request Options​
Only request the data fields you need to minimize response size and improve performance:
// Minimal request for checking existence
const exists = await provider.getObject({
id: objectId,
options: {} // No additional data requested
});
// Full request for detailed analysis
const detailed = await provider.getObject({
id: objectId,
options: {
showType: true,
showOwner: true,
showContent: true,
showPreviousTransaction: true
}
});
Handle Different Object Types​
function parseObjectType(typeString) {
// Example: "0x2::coin::Coin<0x2::sui::SUI>"
const match = typeString.match(/^([^<]+)(?:<(.+)>)?$/);
return {
module: match?.[1],
typeParam: match?.[2]
};
}
Error Handling​
try {
const result = await provider.getObject({ id: objectId });
if (result.error) {
switch (result.error.code) {
case 'objectNotFound':
console.log('Object does not exist');
break;
case 'objectDeleted':
console.log('Object has been deleted');
break;
default:
console.error('Unknown error:', result.error);
}
} else {
// Process object data
processObject(result.data);
}
} catch (error) {
console.error('RPC error:', error);
}
Related Methods​
- sui_executeTransactionBlock - Execute transactions on objects
- suix_getBalance - Query coin balances
Notes​
- Object IDs are unique and immutable across the entire Sui network
- Object versions increment with each modification
- Deleted objects return an error but their ID remains reserved
- The
digest
field provides a hash of the object's content for verification - Storage rebates are refunded when objects are deleted
Need help? Contact our support team or check the Sui documentation.