diff --git a/examples/buy-nft.ts b/examples/buy-nft.ts new file mode 100644 index 0000000..51b6ce4 --- /dev/null +++ b/examples/buy-nft.ts @@ -0,0 +1,22 @@ +import { + deriveEthAddress, + signAndSendTransaction +} from "../src/chains/ethereum"; + +const run = async () => { + const sender = await deriveEthAddress("ethereum,1"); + // TODO - encode call Data from OpenSeaSDK. + // https://github.com/ProjectOpenSea/opensea-js/blob/main/developerDocs/advanced-use-cases.md + const seaportAddress = "0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC"; + const salePrice = 0.05; + const callData = "0x0000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ad31dde0cce000000000000000000000000000262d23a2d916f6cf08e0235315aa51e22d142d0b000000000000000000000000004c00500000ad104d7dbd00e3ae0a5c00560c00000000000000000000000000d4b922e90cb5daa6422ac018acde78dbbe23e4eb0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065f014fb000000000000000000000000000000000000000000000000000000006618e56b0000000000000000000000000000000000000000000000000000000000000000360c6ebe000000000000000000000000000000000000000030c75abf8edea43a0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000a26b00c1f0df003000390027140000faa71900000000000000000000000000000000000000000000000000000000000000400f00e0a3e6be600317f02b2787804d9718ebfbd8016933ab48c8153396a5359038104375bdc311d1f21ed2af05e504c9c16b7482cc2bbed57663dd234ea1a4dd00000000360c6ebe"; + + await signAndSendTransaction( + sender, + seaportAddress, + salePrice, + callData + ); +}; + +run(); diff --git a/examples/set-approval-for-all.ts b/examples/set-approval-for-all.ts new file mode 100644 index 0000000..a00baba --- /dev/null +++ b/examples/set-approval-for-all.ts @@ -0,0 +1,27 @@ +import { + deriveEthAddress, + signAndSendTransaction, +} from "../src/chains/ethereum"; +import { + erc721Interface +} from "../src/utils/interfaces" + + + +const run = async () => { + + const sender = await deriveEthAddress("ethereum,1"); + const value = 0; + const tokenAddress = "0xe66be37f6b446079fe71a497312996dff6bd963f"; + const operator = "0x8d99F8b2710e6A3B94d9bf465A98E5273069aCBd"; + const callData = erc721Interface().encodeFunctionData("setApprovalForAll", [operator, true]); + + await signAndSendTransaction( + sender, + tokenAddress, + value, + callData + ); +}; + +run(); diff --git a/examples/transfer-nft.ts b/examples/transfer-nft.ts new file mode 100644 index 0000000..7414536 --- /dev/null +++ b/examples/transfer-nft.ts @@ -0,0 +1,25 @@ +import { + deriveEthAddress, + signAndSendTransaction +} from "../src/chains/ethereum"; +import { erc721Interface } from "../src/utils/interfaces"; + +const run = async () => { + const sender = await deriveEthAddress("ethereum,1"); + const value = 0; + // TODO retrieve from user: + const tokenAddress = "0xe66be37f6b446079fe71a497312996dff6bd963f"; + const tokenId = 2; + const to = "0x8d99F8b2710e6A3B94d9bf465A98E5273069aCBd"; + + const callData = erc721Interface().encodeFunctionData("safeTransferFrom(address,address,uint256)", [sender, to, tokenId]); + + await signAndSendTransaction( + sender, + tokenAddress, + value, + callData + ); +}; + +run(); diff --git a/src/abis/ERC721.json b/src/abis/ERC721.json new file mode 100644 index 0000000..f98c266 --- /dev/null +++ b/src/abis/ERC721.json @@ -0,0 +1,1446 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "AdminApproved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "AdminRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "approved", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "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": false, + "internalType": "address", + "name": "extension", + "type": "address" + } + ], + "name": "ApproveTransferUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address payable[]", + "name": "receivers", + "type": "address[]" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "basisPoints", + "type": "uint256[]" + } + ], + "name": "DefaultRoyaltiesUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "enabled", + "type": "bool" + } + ], + "name": "ExtensionApproveTransferUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "ExtensionBlacklisted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "ExtensionRegistered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "indexed": false, + "internalType": "address payable[]", + "name": "receivers", + "type": "address[]" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "basisPoints", + "type": "uint256[]" + } + ], + "name": "ExtensionRoyaltiesUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "ExtensionUnregistered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "permissions", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "MintPermissionsUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address payable[]", + "name": "receivers", + "type": "address[]" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "basisPoints", + "type": "uint256[]" + } + ], + "name": "RoyaltiesUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "admin", + "type": "address" + } + ], + "name": "approveAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + } + ], + "name": "blacklistExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAdmins", + "outputs": [ + { + "internalType": "address[]", + "name": "admins", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getApproveTransfer", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getApproved", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getExtensions", + "outputs": [ + { + "internalType": "address[]", + "name": "extensions", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getFeeBps", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getFeeRecipients", + "outputs": [ + { + "internalType": "address payable[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getFees", + "outputs": [ + { + "internalType": "address payable[]", + "name": "", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getRoyalties", + "outputs": [ + { + "internalType": "address payable[]", + "name": "", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "string", + "name": "_symbol", + "type": "string" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "admin", + "type": "address" + } + ], + "name": "isAdmin", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "mintBase", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "mintBase", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "string[]", + "name": "uris", + "type": "string[]" + } + ], + "name": "mintBaseBatch", + "outputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint16", + "name": "count", + "type": "uint16" + } + ], + "name": "mintBaseBatch", + "outputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "mintExtension", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint80", + "name": "data", + "type": "uint80" + } + ], + "name": "mintExtension", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "mintExtension", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "string[]", + "name": "uris", + "type": "string[]" + } + ], + "name": "mintExtensionBatch", + "outputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint80[]", + "name": "data", + "type": "uint80[]" + } + ], + "name": "mintExtensionBatch", + "outputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint16", + "name": "count", + "type": "uint16" + } + ], + "name": "mintExtensionBatch", + "outputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "internalType": "string", + "name": "baseURI", + "type": "string" + } + ], + "name": "registerExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "internalType": "string", + "name": "baseURI", + "type": "string" + }, + { + "internalType": "bool", + "name": "baseURIIdentical", + "type": "bool" + } + ], + "name": "registerExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "admin", + "type": "address" + } + ], + "name": "revokeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "royaltyInfo", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "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": "address", + "name": "extension", + "type": "address" + } + ], + "name": "setApproveTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "enabled", + "type": "bool" + } + ], + "name": "setApproveTransferExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "setBaseTokenURI", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "setBaseTokenURIExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "uri", + "type": "string" + }, + { + "internalType": "bool", + "name": "identical", + "type": "bool" + } + ], + "name": "setBaseTokenURIExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "internalType": "address", + "name": "permissions", + "type": "address" + } + ], + "name": "setMintPermissions", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "address payable[]", + "name": "receivers", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "basisPoints", + "type": "uint256[]" + } + ], + "name": "setRoyalties", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable[]", + "name": "receivers", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "basisPoints", + "type": "uint256[]" + } + ], + "name": "setRoyalties", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + }, + { + "internalType": "address payable[]", + "name": "receivers", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "basisPoints", + "type": "uint256[]" + } + ], + "name": "setRoyaltiesExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "setTokenURI", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + }, + { + "internalType": "string[]", + "name": "uris", + "type": "string[]" + } + ], + "name": "setTokenURI", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + }, + { + "internalType": "string[]", + "name": "uris", + "type": "string[]" + } + ], + "name": "setTokenURIExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "setTokenURIExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "prefix", + "type": "string" + } + ], + "name": "setTokenURIPrefix", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "prefix", + "type": "string" + } + ], + "name": "setTokenURIPrefixExtension", + "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": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenData", + "outputs": [ + { + "internalType": "uint80", + "name": "", + "type": "uint80" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenExtension", + "outputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "extension", + "type": "address" + } + ], + "name": "unregisterExtension", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index 7ffd9db..35a9b3a 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -61,7 +61,8 @@ async function queryGasPrice() { // This is NOT a recommended practice for production environments. const buffer = BigInt(2 * 1e9); // Example buffer of 2 Gwei, assuming the API values are in WEI const maxFeePerGas = maxPriorityFeePerGas + buffer; - + const returnData = { maxFeePerGas, maxPriorityFeePerGas }; + console.log("Gas estimates", returnData) return { maxFeePerGas, maxPriorityFeePerGas }; } @@ -76,24 +77,29 @@ export const createPayload = async ( const transactionData = { nonce, - gasLimit: 1000000, - maxFeePerGas: maxFeePerGas, - maxPriorityFeePerGas: maxPriorityFeePerGas, to: receiver, value: BigInt(web3.utils.toWei(amount, "ether")), data: data || "0x", + maxFeePerGas, + maxPriorityFeePerGas, }; - - console.log(transactionData); - - const transaction = FeeMarketEIP1559Transaction.fromTxData(transactionData, { + const estimatedGas = await provider.estimateGas({ + ...transactionData, + from: sender, + }); + console.log(`Using gas estimate of at ${estimatedGas} GWei`); + const transactionDataWithGasLimit = { + ...transactionData, + gasLimit: BigInt(estimatedGas.toString()), + }; + console.log("TxData:", transactionDataWithGasLimit); + const transaction = FeeMarketEIP1559Transaction.fromTxData(transactionDataWithGasLimit, { common, }); const payload = Array.from( new Uint8Array(transaction.getHashedMessageToSign().slice().reverse()) ); - return { transaction, payload }; }; @@ -124,7 +130,8 @@ export const relayTransaction = async ( ) => { const serializedTx = bytesToHex(signedTransaction.serialize()); const relayed = await web3.eth.sendSignedTransaction(serializedTx); - return relayed.transactionHash; + console.log("Transaction Confirmed:", relayed.transactionHash); + return relayed.transactionHash; }; export const requestSignature = async (payload: number[], path: string) => { @@ -172,6 +179,7 @@ export const signAndSendTransaction = async ( path: string; } ) => { + console.log("Create Paylod for", sender); const { transaction, payload } = await createPayload( sender, receiver, @@ -185,6 +193,6 @@ export const signAndSendTransaction = async ( ); const signature = reconstructSignature(transaction, big_r, big_s, sender); - + console.log("Relaying signed tx to EVM..."); await relayTransaction(signature); }; diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts new file mode 100644 index 0000000..2313833 --- /dev/null +++ b/src/utils/interfaces.ts @@ -0,0 +1,6 @@ +import { ethers } from "ethers"; +import erc721ABI from '../abis/ERC721.json'; + +export function erc721Interface(): ethers.utils.Interface { + return new ethers.utils.Interface(erc721ABI); +} diff --git a/tsconfig.json b/tsconfig.json index bd56cd2..91e66b4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "jsx": "react-jsx", "allowJs": true, "moduleResolution": "Node", + "resolveJsonModule": true, "declaration": true, "outDir": "dist",