-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add ERC1155 support with balance fetching and transfer function… #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d2b07b7
feat: add ERC1155 support with balance fetching and transfer function…
dev2-nomo 00b6eca
feat: add ERC1155 export to EVM module
dev2-nomo 4bce710
refactor: rename 'account' parameter to 'address' for consistency in …
dev2-nomo 799388a
feat: add isErc1155 function to check ERC1155 token support and inclu…
dev2-nomo c3ad86a
feat: add ERC1155 transaction fetching and balance handling in EVM mo…
dev2-nomo ca9fe21
fix: update tokenValue parsing to default to zero instead of -1 in Et…
dev2-nomo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,385 @@ | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:walletkit_dart/walletkit_dart.dart'; | ||
|
|
||
| final contractAbiErc1155 = ContractABI.fromAbi('''[ | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "account", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "id", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "balanceOf", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address[]", | ||
| "name": "accounts", | ||
| "type": "address[]" | ||
| }, | ||
| { | ||
| "internalType": "uint256[]", | ||
| "name": "ids", | ||
| "type": "uint256[]" | ||
| } | ||
| ], | ||
| "name": "balanceOfBatch", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "uint256[]", | ||
| "name": "", | ||
| "type": "uint256[]" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "account", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "address", | ||
| "name": "operator", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "name": "isApprovedForAll", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "bool", | ||
| "name": "", | ||
| "type": "bool" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "from", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "address", | ||
| "name": "to", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "uint256[]", | ||
| "name": "ids", | ||
| "type": "uint256[]" | ||
| }, | ||
| { | ||
| "internalType": "uint256[]", | ||
| "name": "amounts", | ||
| "type": "uint256[]" | ||
| }, | ||
| { | ||
| "internalType": "bytes", | ||
| "name": "data", | ||
| "type": "bytes" | ||
| } | ||
| ], | ||
| "name": "safeBatchTransferFrom", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "from", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "address", | ||
| "name": "to", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "id", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "amount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "bytes", | ||
| "name": "data", | ||
| "type": "bytes" | ||
| } | ||
| ], | ||
| "name": "safeTransferFrom", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "operator", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "bool", | ||
| "name": "approved", | ||
| "type": "bool" | ||
| } | ||
| ], | ||
| "name": "setApprovalForAll", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "bytes4", | ||
| "name": "interfaceId", | ||
| "type": "bytes4" | ||
| } | ||
| ], | ||
| "name": "supportsInterface", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "bool", | ||
| "name": "", | ||
| "type": "bool" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "id", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "uri", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "string", | ||
| "name": "", | ||
| "type": "string" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "account", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "operator", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "bool", | ||
| "name": "approved", | ||
| "type": "bool" | ||
| } | ||
| ], | ||
| "name": "ApprovalForAll", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "operator", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "from", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "to", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256[]", | ||
| "name": "ids", | ||
| "type": "uint256[]" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256[]", | ||
| "name": "values", | ||
| "type": "uint256[]" | ||
| } | ||
| ], | ||
| "name": "TransferBatch", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "operator", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "from", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "to", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "id", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "value", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "TransferSingle", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": false, | ||
| "internalType": "string", | ||
| "name": "value", | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "uint256", | ||
| "name": "id", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "URI", | ||
| "type": "event" | ||
| } | ||
| ] | ||
|
|
||
| '''); | ||
|
|
||
| class ERC1155Contract extends InternalContract { | ||
| ERC1155Contract({ | ||
| required super.contractAddress, | ||
| required super.rpc, | ||
| }) : super( | ||
| abi: contractAbiErc1155, | ||
| ); | ||
|
|
||
| Future<BigInt> balanceOf({ | ||
| required String address, | ||
| required BigInt tokenID, | ||
| }) async { | ||
| final function = abi.functions[0]; | ||
| final response = await readSafe( | ||
| function: function.addValues(values: [address, tokenID]), | ||
| ); | ||
| return response.outputs.first.castValue<BigInt>(); | ||
| } | ||
|
|
||
| Future<List<BigInt>> balanceOfBatch({ | ||
| required List<String> accounts, | ||
| required List<BigInt> tokenIDs, | ||
| }) async { | ||
| if (accounts.length != tokenIDs.length) { | ||
| throw ArgumentError('accounts and tokenIDs must have the same length'); | ||
| } | ||
| final function = abi.functions[1]; | ||
| final response = await readSafe( | ||
| function: function.addValues(values: [accounts, tokenIDs]), | ||
| ); | ||
| return response.outputs.first.castValue<List<BigInt>>(); | ||
| } | ||
|
|
||
| Future<String> getUri({ | ||
| required BigInt tokenID, | ||
| }) async { | ||
| final function = abi.functions[7]; | ||
| final response = await readSafe( | ||
| function: function.addValues(values: [tokenID]), | ||
| ); | ||
| return response.outputs.first.castValue<String>(); | ||
| } | ||
|
|
||
| Future<String> safeTransferFrom({ | ||
| required String sender, | ||
| required String to, | ||
| required BigInt tokenID, | ||
| required BigInt amount, | ||
| required Uint8List seed, | ||
| Uint8List? data, | ||
| EvmFeeInformation? feeInfo, | ||
| List<AccessListItem>? accessList, | ||
| }) async { | ||
| final function = abi.functions[4]; | ||
| return await interact( | ||
| function: function.addValues( | ||
| values: [sender, to, tokenID, amount, data ?? Uint8List(0)]), | ||
| sender: sender, | ||
| seed: seed, | ||
| feeInfo: feeInfo, | ||
| accessList: accessList, | ||
| ); | ||
| } | ||
| } | ||
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add comprehensive input validation for safe transfer.
The method uses a magic number for function index and lacks important input validations.
Apply this diff to improve the implementation:
📝 Committable suggestion