Skip to content

Commit

Permalink
Examples: Buy, Transfer, SetApproval (#1)
Browse files Browse the repository at this point in the history
* transfer, set approval and hardcoded buy

* buy-nft gas estimates
  • Loading branch information
bh2smith authored Mar 12, 2024
1 parent f0760c0 commit 4811751
Show file tree
Hide file tree
Showing 7 changed files with 1,546 additions and 11 deletions.
22 changes: 22 additions & 0 deletions examples/buy-nft.ts
Original file line number Diff line number Diff line change
@@ -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();
27 changes: 27 additions & 0 deletions examples/set-approval-for-all.ts
Original file line number Diff line number Diff line change
@@ -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();
25 changes: 25 additions & 0 deletions examples/transfer-nft.ts
Original file line number Diff line number Diff line change
@@ -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();
Loading

0 comments on commit 4811751

Please sign in to comment.