-
Notifications
You must be signed in to change notification settings - Fork 289
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
feat: add action to list nfts on opensea (ts) #261
base: main
Are you sure you want to change the base?
Conversation
🟡 Heimdall Review Status
|
The EstimateGasExecutionError bug was also fixed in #283. |
this.networkConfig = | ||
config.networkId === "base-sepolia" | ||
? { | ||
rpcUrl: "https://sepolia.base.org", | ||
openseaUrl: "https://testnets.opensea.io/assets/base_sepolia", | ||
chain: Chain.BaseSepolia, | ||
} | ||
: { | ||
rpcUrl: "https://main.base.org", | ||
openseaUrl: "https://opensea.io/assets/base", | ||
chain: Chain.Mainnet, | ||
}; | ||
|
||
if (config.networkId !== "base-sepolia" && config.networkId !== "base-mainnet") { | ||
throw new Error("Unsupported network. Only base-sepolia and base-mainnet are supported."); | ||
} | ||
|
||
// Initialize ethers signer required for OpenSea SDK | ||
const provider = new JsonRpcProvider(this.networkConfig.rpcUrl); | ||
const walletWithProvider = new Wallet(config.privateKey!, provider); | ||
this.walletWithProvider = walletWithProvider; | ||
|
||
const openseaSDK = new OpenSeaSDK(walletWithProvider, { |
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.
Is it required to use an ethers.js provider here instead of Viem? If so, should we create an ethersWalletProvider
. My concern here is that the proposed configuration forces developers to instantiate a wallet provider + a bespoke wallet just for this action provider
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.
Yes seems like ethers provider is needed, see: https://github.com/ProjectOpenSea/seaport-js/blob/bd3e0fac60dc764e5235df4fcb8e2a1cc84a7624/src/seaport.ts#L98
You mean creating a ethersWalletProvider similar to viemWalletProvider and then do sth like:
export class OpenseaActionProvider extends ActionProvider <ethersWalletProvider >
?
I think the problem is then that OpenseaActionProvider and eg cdpWalletActionProvider could not be used at the same time here:
agentkit/typescript/examples/langchain-cdp-chatbot/chatbot.ts
Lines 97 to 124 in 6fab218
const agentkit = await AgentKit.from({ | |
walletProvider, | |
actionProviders: [ | |
wethActionProvider(), | |
pythActionProvider(), | |
walletActionProvider(), | |
erc20ActionProvider(), | |
erc721ActionProvider(), | |
cdpApiActionProvider({ | |
apiKeyName: process.env.CDP_API_KEY_NAME, | |
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"), | |
}), | |
cdpWalletActionProvider({ | |
apiKeyName: process.env.CDP_API_KEY_NAME, | |
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"), | |
}), | |
// Only add OpenSea provider if API key is configured | |
...(process.env.OPENSEA_API_KEY | |
? [ | |
openseaActionProvider({ | |
apiKey: process.env.OPENSEA_API_KEY, | |
networkId: walletProvider.getNetwork().networkId, | |
privateKey: await (await walletProvider.getWallet().getDefaultAddress()).export(), | |
}), | |
] | |
: []), | |
], | |
}); |
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.
Thanks for clarifying this makes sense.
I improved the provider setup such that a default provider is used and a private key is sufficient to setup OpenseaActionProvider |
@phdargen please rebase onto latest master. The changes to action provider initialization LGTM |
@John-peterson-coinbase Done! |
Why? What?
Adds new OpenseaActionProvider to handle interactions with opensea.
So far only one action is implemented (list_nft) that creates a listing on opensea.
Additional actions like accept/create offer may be added in the future.
This implementation uses the opensea-js sdk that is added as new dependency and requires an opensea api key (https://docs.opensea.io/reference/api-overview). The new action is added in the chatbot.ts example, only if an OPENSEA_API_KEY is set.
The OpenSea SDK requires an ethers signer which is created when initialising OpenseaActionProvider with the privateKey to the account holding the NFT. In the chatbot.ts example, I extract the privateKey from the CdpWalletProvider. This is a bit of a hack but I couldn't find a way to directly use a EvmWalletProvider to create a ethers signer. Suggestions are welcome.
What changed?
EstimateGasExecutionError: Execution reverted for an unknown reason
for mint nft action, similar to the issue Call to estimateGas in prepareTransaction of CdpWalletProvider uses address 0 #238.Fixed after changing:
account: this.#publicClient.account
toaccount: this.#address as
0x${string}Network support
Checklist
How has it been tested?