Portal API methods
Portal API's convenient helper methods are designed to streamline data retrieval from the Portal REST API.
portal.getNFTAssets
portal.getNFTAssets
Fetches the asset balances (native and token balances) for a specified blockchain. It provides detailed information on the native balance and token balances held by a given address on the specified chain.
Task {
do {
let nfts = try await portal.getNftAssets(chainId)
} catch {
// Handle any errors.
}
}
Example API response
Please note that this is purely fictitious response data.
{
"nativeBalance": {
"balance": "0.10991767582513721",
"decimals": 18,
"name": "Ether",
"rawBalance": "109917675825137210",
"symbol": "ETH",
"metadata": {
"logo": "https://cdn.moralis.io/eth/0x.png",
"thumbnail": "https://cdn.moralis.io/eth/0x_thumb.png"
}
},
"tokenBalances": [
{
"balance": "0.0199",
"decimals": 18,
"name": "Wrapped Ether",
"rawBalance": "19900000000000000",
"symbol": "WETH",
"metadata": {
"tokenAddress": "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
"verifiedContract": false,
"totalSupply": "48148.648311179713152621",
"rawTotalSupply": "48148648311179713152621",
"percentageRelativeToTotalSupply": 0.00004133033989114
}
}
],
"nfts": [
{
"nftId": "ethereum.0x123abc...def456.1234",
"name": "Cosmic Kitty #1234",
"description": "A rare, interstellar feline NFT from the Cosmic Kitties collection.",
"imageUrl": "https://example.com/images/cosmic-kitty-1234.png",
"chainId": "eip155:1",
"contractAddress": "0x123abc...def456",
"tokenId": "1234",
"collection": {
"name": "Cosmic Kitties",
"description": "A collection of 10,000 unique space-faring felines.",
"imageUrl": "https://example.com/images/cosmic-kitties-logo.png"
},
"lastSale": {
"price": 1500000000000000000,
"currency": "ETH",
"date": "2024-07-15T14:30:00Z"
},
"rarity": {
"rank": 42,
"score": 0.95
},
"floorPrice": {
"price": 1200000000000000000,
"currency": "ETH"
},
"detailedInfo": {
"ownerCount": 1,
"tokenCount": 1,
"createdDate": "2024-01-01T00:00:00Z",
"attributes": [
{
"traitType": "Fur Color",
"value": "Nebula Purple",
"displayType": null
},
{
"traitType": "Eye Color",
"value": "Starlight Blue",
"displayType": null
},
{
"traitType": "Accessory",
"value": "Jetpack",
"displayType": null
}
],
"owners": [
{
"ownerAddress": "0xabcdef...123456",
"quantity": 1,
"firstAcquiredDate": "2024-07-15T14:30:00Z",
"lastAcquiredDate": "2024-07-15T14:30:00Z"
}
],
"extendedCollectionInfo": {
"bannerImageUrl": "https://example.com/images/cosmic-kitties-banner.png",
"externalUrl": "https://cosmickitties.io",
"twitterUsername": "@CosmicKitties",
"discordUrl": "https://discord.gg/cosmickitties",
"instagramUsername": "@cosmic.kitties",
"mediumUsername": "@CosmicKittiesNFT",
"telegramUrl": "https://t.me/cosmickitties",
"distinctOwnerCount": 8500,
"distinctNftCount": 10000,
"totalQuantity": 10000
},
"extendedSaleInfo": {
"fromAddress": "0x98765...fedcba",
"toAddress": "0xabcdef...123456",
"priceUsdCents": 270000,
"transaction": "0xfedcba...987654",
"marketplaceId": "opensea",
"marketplaceName": "OpenSea"
},
"marketplaceInfo": [
{
"marketplaceId": "opensea",
"marketplaceName": "OpenSea",
"marketplaceCollectionId": "cosmic-kitties",
"nftUrl": "https://opensea.io/assets/ethereum/0x123abc...def456/1234",
"collectionUrl": "https://opensea.io/collection/cosmic-kitties",
"verified": true,
"floorPrice": {
"value": 1200000000000000000,
"paymentToken": {
"paymentTokenId": "ethereum",
"name": "Ethereum",
"symbol": "ETH",
"address": null,
"decimals": 18
},
"valueUsdCents": 270000
}
}
],
"mediaInfo": {
"previews": {
"imageSmallUrl": "https://example.com/images/cosmic-kitty-1234-small.png",
"imageMediumUrl": "https://example.com/images/cosmic-kitty-1234-medium.png",
"imageLargeUrl": "https://example.com/images/cosmic-kitty-1234-large.png",
"imageOpengraphUrl": "https://example.com/images/cosmic-kitty-1234-og.png",
"blurhash": "L9B4IwofV@of~qofM{of00WB%Mj[",
"predominantColor": "#8A2BE2"
},
"animationUrl": "https://example.com/animations/cosmic-kitty-1234.mp4",
"backgroundColor": "#000000"
}
}
}
]
}
portal.getTransactions
portal.getTransactions
Fetches a list of the client's transaction history ordered by blockTimestamp
descending (latest transactions will come first). This includes both inbound and outbound transactions.
Task {
do {
let transactions = try await portal.getTransactions(chainId)
} catch {
// Handle any errors.
}
}
Arguments can also be provided:
chainId
: ID of the chain to retrieve transactions from. Defaults to your Portal instance's chainId if not provided.limit
: (Optional) The maximum number of transactions to return.offset
: (Optional) The number of transactions to skip before starting to return.order
: (Optional) Order in which to return the transactions. Either"asc"
or"desc"
.
Response structure
The response from the API request is a JSON array of objects. Each object represents a unique transaction and consists of the following fields:
blockNum
: A string representing the hexadecimal number of the block in which the transaction occurred.uniqueId
: A unique string that uniquely identifies this transaction. It is constructed from the transaction's hash and category.hash
: A string that represents the hash of the transaction. This hash can be used as a unique identifier for the transaction on the blockchain.from
: A string that represents the address of the sender of the transaction.to
: A string that represents the address of the receiver of the transaction.value
: A floating-point number that represents the value of the transaction in the asset type mentioned in theasset
field.erc721TokenId
: This field is null for non-ERC721 transactions. For ERC721 transactions, this field contains the unique identifier of the ERC721 token.erc1155Metadata
: This field is null for non-ERC1155 transactions. For ERC1155 transactions, this field contains any metadata associated with the ERC1155 token.tokenId
: This field is null for non-token transactions. For token transactions, it represents the unique identifier of the token involved in the transaction.asset
: A string that represents the type of asset that was transferred in the transaction. For example, the asset type could be "ETH" when transferring ETH from one address to another one.category
: A string that represents the category of the transaction. Can be any of the following: "external", "internal", "erc20", "erc721", "erc1155", or "specialnft".rawContract
: An object that contains raw contract details:value
: A hexadecimal string representing the raw value of the transaction.address
: The address of the contract. This is null for non-contract transactions.decimal
: A hexadecimal string representing the number of decimal places that thevalue
field should be calculated to.
metadata
: An object that contains additional details about the transaction:blockTimestamp
: Timestamp of the block from which the transaction event originated (ISO-formatted timestamp).
chainId
: An integer denoting the blockchain network identifier.
In Swift, the completion handler returns Result<[Transaction]>
.
Example API response
Please note that this is purely fictitious response data.
[
{
"blockNum": "0x1a2b3c",
"uniqueId": "0xabc123def456ghi789jkl012mno345pqr678stu901vwx234yza567b:internal",
"hash": "0xabc123def456ghi789jkl012mno345pqr678stu901vwx234yza567b",
"from": "0x1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0",
"to": "0x0a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1",
"value": 0.257842,
"erc721TokenId": null,
"erc1155Metadata": null,
"tokenId": null,
"asset": "ETH",
"category": "internal",
"rawContract": {
"value": "0x37fa23dbc90000",
"address": null,
"decimal": "0x12"
},
"metadata": {
"blockTimestamp": "2023-08-30T23:11:24.000Z"
}
},
{
"blockNum": "0x2b3c4d",
"uniqueId": "0xdef456ghi789jkl012mno345pqr678stu901vwx234yza567bca123:internal",
"hash": "0xdef456ghi789jkl012mno345pqr678stu901vwx234yza567bca123",
"from": "0x2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1",
"to": "0x1a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1",
"value": 0.367925,
"erc721TokenId": null,
"erc1155Metadata": null,
"tokenId": null,
"asset": "ETH",
"category": "internal",
"rawContract": {
"value": "0x50ca24dbfc4000",
"address": null,
"decimal": "0x12"
},
"metadata": {
"blockTimestamp": "2023-08-30T23:11:24.000Z"
}
}
]
portal.getBalances
portal.getBalances
Fetches a list of the client's ERC20 token balances.
Task {
do {
let erc20Balances = try await portal.getBalances(chainId)
} catch {
// Handle any errors.
}
}
Response structure
The response from the API request is a JSON array of balance objects. Each balance object provides information about the balance of a specific asset that the client owns on different contracts.
Each balance object contains the following fields:
contractAddress
: A string representing the address of the smart contract which manages the asset.balance
: A string representing the balance of the asset that the user owns, held at the respective contract address. It's in the smallest denomination of the asset (e.g. 'wei' in the case of Ether and many ERC20 tokens).
In Swift, the completion handler returns Result<[Balance]>
.
Example API response
Please note that this is purely fictitious response data.
[
{
"contractAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"balance": "0"
},
{
"contractAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"balance": "12345"
}
]
poportal.buildEip155Transaction
poportal.buildEip155Transaction
Creates an unsigned eip155 transaction for transferring assets to another address on a specific chain. You can then use this unsigned eip155 transaction to sign and submit the eip155 transaction.
Task {
do {
let buildTransactionParam = BuildTransactionParam(
to: "eip155 address",
token: "ETH",
amount: "1.0"
)
let eip155Transaction = try await portal.buildEip155Transaction(chainId: chainId, params: buildTransactionParam)
} catch {
// Handle any errors.
}
}
Example API response
Please note that this is purely fictitious response data.
{
"transaction": {
"from": "0x54968898742c08da211a1cd355447cd1f37f0649",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"data": "0xa9059cbb000000000000000000000000dfd8302f44727a6348f702ff7b594f127de3a9020000000000000000000000000000000000000000000000000000000000002710"
},
"metadata": {
"amount": "0.01",
"fromAddress": "0x54968898742c08da211a1cd355447cd1f37f0649",
"toAddress": "0xdFd8302f44727A6348F702fF7B594f127dE3A902",
"tokenAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"tokenDecimals": 6,
"rawAmount": "10000"
}
}
portal.buildSolanaTransaction
portal.buildSolanaTransaction
Creates an unsigned eip155 transaction for transferring assets to another address on a specific chain. You can then use this unsigned eip155 transaction to sign and submit the eip155 transaction.
Task {
do {
let buildTransactionParam = BuildTransactionParam(
to: "solana address",
token: "SOL",
amount: "1.0"
)
let solanaTransaction = try await portal.buildSolanaTransaction(chainId: chainId, params: buildTransactionParam)
} catch {
// Handle any errors.
}
}
Example API response
Please note that this is purely fictitious response data.
{
"transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAUIXIcyVRnqtuJq4VAVZQPX4M5MFtpcAzLmaNCC62aV/5Ftzsmzlp2NKI8Dlj+MKJ7LBQsJ9iiXAult3S/Y/4YTRgjDL4wY8hJ13iBEAciC0uIGJEPr+VGVf2qQqxBytKhwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB1aziYgQ4rYMUc0A5K2y4oefHN83MNdiTvNPqWosjPIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZxvp6877brTo9ZfNqq8l0MbG75MLS9uDkfKYCA0UvXWEG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqSgizMJvj1c1WJPJuxDQWi6VG4dp6Fq930FKOQcI25XjAgUGAAIEBgMHAAcDAQIACQMQJwAAAAAAAA==",
"metadata": {
"amount": "0.01",
"fromAddress": "7EC5TEEAcDseLH6PyqKkPiBasVnsdmrRbRHjN3zkkHFW",
"toAddress": "8APEEA4SHrfGteABQcUmH2yEHy7nEe8DqgvmKGAStHR",
"tokenMintAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"tokenDecimals": 6,
"tokenProgramId": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
"tokenExtensions": [
"ConfidentialTransferAccount",
"ConfidentialTransferMint",
"CpiGuard",
"DefaultAccountState",
"GroupMemberPointer",
"GroupPointer",
"ImmutableOwner",
"InterestBearingConfig",
"MemoTransfer",
"MetadataPointer",
"MintCloseAuthority",
"NonTransferable",
"NonTransferableAccount",
"PermanentDelegate",
"TokenGroup",
"TokenGroupMember",
"TokenMetadata",
"TransferFeeAmount",
"TransferFeeConfig",
"TransferHook",
"TransferHookAccount",
"Uninitialized",
],
"rawAmount": "10000",
"lastValidBlockHeight": "260129177",
"serializedTransactionBase64Encoded": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAUIXIcyVRnqtuJq4VAVZQPX4M5MFtpcAzLmaNCC62aV/5Ftzsmzlp2NKI8Dlj+MKJ7LBQsJ9iiXAult3S/Y/4YTRgjDL4wY8hJ13iBEAciC0uIGJEPr+VGVf2qQqxBytKhwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB1aziYgQ4rYMUc0A5K2y4oefHN83MNdiTvNPqWosjPIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZxvp6877brTo9ZfNqq8l0MbG75MLS9uDkfKYCA0UvXWEG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqSgizMJvj1c1WJPJuxDQWi6VG4dp6Fq930FKOQcI25XjAgUGAAIEBgMHAAcDAQIACQMQJwAAAAAAAA==",
"serializedTransactionBase58Encoded": "4c5ErVEQWyXMS7yGF2TJaJBf7Vk3bkdaXx6LrCS3xkeLUPWnJMde1CmjFFxEEwbwLjX6N2u2RNpNFhTPML7ow4ZDpUPB5NeocD5GDDPQb9Sy7BPTEMQH7QGXEDx8pfYmk7Z3yYTi7Wz6CsgoKgwhQTGRqCr6mhacTYVAwUpiptsASucz6hqkffZx7P96UPrU3vwL1QMYjLXKYYduuiqket5bt6uCRyF5cchdjir2LPTaqdLsKehDsFPh6ko45vJ4QuXZmeMyeF1fxECfjoj1N8wazVL57Ct9t5CKWXcWrXJkTzksGwMJ7CJQCUrMT7CGswzd9pwj55Lxcq55KcsGvTsu9NEo6dCs4ZFDXuXBexg7C3XNTf5GgsqBEi5MQVcZicUQb3EdS1j8ShTiNyiVkG2JEkvHQc4FZGQvSqrjgaUoi7FSfMRVeB6vWWwtnUfsGea1UcarfrFN8BcvuZrHNA5pyfC89iJpm55GRqgZFFupCCoWG3sJ47spU19oGEoAYD4pw6TJw",
"unsignedTransactionMessage": {
"signatures": null,
"message": {
"accountKeys": [
"7EC5TEEAcDseLH6PyqKkPiBasVnsdmrRbRHjN3zkkHFW",
"8PeKkecAjt1VgQNg1acdhgrajDJDB9uEDXP6MvRC8WAZ",
"bCtKaS7SecyaiTDL388bnLyMmgFvGdxmLmeEhcoq5Eo",
"11111111111111111111111111111111",
"8APEEA4SHrfGteABQcUmH2yEHy7nEe8DqgvmKGAStHR",
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
],
"header": {
"numRequiredSignatures": 1,
"numReadonlySignedAccounts": 0,
"numReadonlyUnsignedAccounts": 5
},
"instructions": [
{
"programIdIndex": 5,
"accounts": [
0,
2,
4,
6,
3,
7
],
"data": ""
},
{
"programIdIndex": 7,
"accounts": [
1,
2,
0
],
"data": "3GAG5eogvTjV"
}
],
"recentBlockhash": "3hg5wAbN1FYh5fGANDpCgWMDG1NPMYmNwdDiYTqinFUv"
}
}
}
}
Last updated