Rust client to Opensea's APIs and Ethereum smart contracts

Overview

opensea.rs

Rust bindings & CLI to the Opensea API and Contracts

Github Actions

CLI Usage

Run cargo r -- --help to get the top level help menu:

opensea-cli 0.1.0
Choose what NFT subcommand you want to execute

USAGE:
    opensea-cli <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    buy       Purchase 1 or more NFTs, with optional Flashbots support
    deploy    Deploy the Ethereum contract for doing consistency checks inside a Flashbots bundle
    help      Prints this message or the help of the given subcommand(s)
    prices    Get OpenSea orderbook information about the token

To view each individual subcommand's help menu, run: opensea-cli <subcommand name> --help

Buying NFT(s)

Here's an example command for purchasing some ERC1155 NFTs using Flashbots:

cargo run buy \
    --nft.erc1155 \
    --nft.address "0xTheNFTAddress" \
    --nft.ids 1 --nft.ids 2 --nft.ids 3 \
    --eth.private_key "0xMyPrivateKey" \
    --eth.url http://localhost:8545 \
    --flashbots.bribe 1000000000000000000 \
    --flashbots.bribe_receiver 0xYourBriberContract

Instead of providing nft.ids, you can also provide a CSV file via the --nft.ids_path command, where the first column contains the id of the NFT and the second column contains the quantity of purchased NFT.

Here's an ERC1155 example (which also requires passing the --nft.erc1155 flag)

1,1
2,5
3,2

And an ERC721 example

1
2
3

Flashbots Support: This will proceed to create a Flashbots bundle with 4 transactions: 3 NFT take orders on OpenSea, and a 4th transaction which sends the bribe to the briber contract while also doing consistency checks that we have received the NFTs

Public Mempool: If you omit the Flashbots parameters, it'll proceed to submit the transactions normally via the public mempool.

Development

Rust Toolchain

We use the stable Rust toolchain. Install by running: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Building & testing

cargo check
cargo test
cargo doc --open
cargo build [--release]

Features

  • Opensea API
  • Opensea Types (Orders etc.)
  • Opensea Contract clients
    • ERC721
    • ERC1155
    • Fill a Sell order
    • Generalize the API to arbitrary Opensea marketplace schemas
  • CLI for operations
    • Flashbots contract deployer
    • Query prices
    • Purchase NFT(s)
    • Sniping drops (pre-configuring the target and looping)

Running ignored tests

  1. Create a hardhat.config.js file and fork from mainnet at this block:
export default {
  networks: {
    hardhat: {
      forking: {
        url: "https://eth-mainnet.alchemyapi.io/v2/<YOUR API KEY>",
        blockNumber: 13037331,
      },
      hardfork: "london",
    }
  }
}
  1. cargo test --ignored

Acknowledgements

Briber.sol contract written by Anish Agnihotri

Comments
  • Integer overflow when casting to u64

    Integer overflow when casting to u64

    When I provide "long" (widespread at OpenSea shared contract) nft.ids, it returns error. E.g.

    cargo run prices --nft.address 0x495f947276749ce646f68ac8c248420045cb7b5e --nft.ids 96475701516811371815276227977766131962669887094423874457871336890511147401221
    

    Output:

    thread 'main' panicked at 'Integer overflow when casting to u64', /Users/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.9.1/src/lib.rs:38:1
    

    Same happens if provide via csv --nft.ids_path. Seems like it's trying to convert this string to integer somewhere.

    opened by kirmishov 1
  • remove unvalidated fee fields on buy side

    remove unvalidated fee fields on buy side

    Am fairly sure the buy fee params (were previously mirroring sell fee params) are not checked with the default fee setup opensea uses. https://etherscan.io/tx/0x42bf65ad17af8926c86444b0ea5a2177eb44976e71fe5061ff6e5e2ea78dbf02 atomicMatch_ on this commit and no buy fee. It doesn't allow fee avoidance but saves 2 nonezero bytes of calldata

    opened by ghost 0
  • "root path '{}' is not absolute"

    Hi there.

    Running cargo check is giving me the following error:

       Compiling ethers-contract-abigen v0.5.4
    error: 1 positional argument in format string, but no arguments were given
      --> (redacted)/.cargo/registry/src/github.com-1ecc6299db9ec823/ethers-contract-abigen-0.5.4/src/source.rs:93:46
       |
    93 |             .map_err(|_| anyhow!("root path '{}' is not absolute"))?;
       |                                              ^^
    
    error: could not compile `ethers-contract-abigen` due to previous error
    
    opened by moxley01 0
  • current price deserialization u256_from_dec_str

    current price deserialization u256_from_dec_str

    Hi,

    First of all thanks for opensourcing this. I am totally new to rust and experiencing some issues.

    But a notable one (that might actually be an issue) is the following :

    #[serde(deserialize_with = "u256_from_dec_str")] pub current_price: U256,

    has problems with how I receive price from opensea as follows :

    "current_price": "65000000000000000.00000000000"

    To replicate the error you can just add the price above in orders.json and run cargo test

    For now I did fix it like :

    pub fn u256_from_dec_str<'de, D>(deserializer: D) -> Result<U256, D::Error>
    where
     D: de::Deserializer<'de>,
    {
     let s: &str = de::Deserialize::deserialize(deserializer)?;
     let s: &str = &s.replace(".", "");
     U256::from_dec_str(s).map_err(de::Error::custom)
    }```
    opened by OTPkat 0
  • Error 0432 & 0599

    Error 0432 & 0599

    C:\Users\Windows\Documents\opensea-rs-master>cargo run prices Compiling ethers-providers v0.5.4 error[E0432]: unresolved import tokio::net::UnixStream --> C:\Users\Windows.cargo\registry\src\github.com-1ecc6299db9ec823\ethers-providers-0.5.4\src\transports\ipc.rs:22:5 | 22 | net::UnixStream, | ^^^^^^^^^^^^^^^ no UnixStream in net

    error[E0599]: no function or associated item named connect found for struct ipc::Ipc in the current scope --> C:\Users\Windows.cargo\registry\src\github.com-1ecc6299db9ec823\ethers-providers-0.5.4\src\provider.rs:919:31 | 919 | let ipc = crate::Ipc::connect(path).await?; | ^^^^^^^ function or associated item not found in ipc::Ipc | ::: C:\Users\Windows.cargo\registry\src\github.com-1ecc6299db9ec823\ethers-providers-0.5.4\src\transports\ipc.rs:30:1 | 30 | pub struct Ipc { | -------------- function or associated item connect not found for this | = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item connect, perhaps you need to implement one of them: candidate #1: hyper::client::connect::sealed::Connect candidate #2: hyper::client::connect::sealed::ConnectSvc

    opened by JohnnyOmm 1
  • add argument custom gas limit

    add argument custom gas limit

    Would be great to have an option to set gas limit w/ cargo run buy --eth.gas

    cause 300k gas limit nowadays may return [Out of gas] error.

    https://github.com/gakonst/opensea-rs/blob/master/opensea/src/lib.rs#L200

    opened by kirmishov 0
Owner
Georgios Konstantopoulos
blockchain scalability, information security and mechanism design. That Layer 2 guy. Aspiring Rustacean.
Georgios Konstantopoulos
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts ‒ a smart contract modu

Parity Technologies 73 Dec 30, 2022
Rust project for working with ETH - Ethereum transactions with Rust on Ganache and also deploy smart contracts :)

Just a test project to work with Ethereum but using Rust. I'm using plain Rust here, not Foundry. In future we will use Foundry. Hope you're already f

Akhil Sharma 2 Dec 20, 2022
RGB smart contracts: client-facing library & command-line for desktop and mobile

RGB smart contracts RGB is confidential & scalable client-validated smart contracts for Bitcoin & Lightning. It embraces the concepts of private & mut

RGB: scalable & private smart contracts for bitcoin & lightning 4 Mar 15, 2023
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Aurora 125 Dec 3, 2022
A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Neodyme 165 Dec 18, 2022
Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

Jacob 27 Dec 17, 2022
Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

NEARFoundation 9 Aug 3, 2022
A framework for publishing, deploying, invoking, and upgrading soroban smart contracts

SmartDeploy A framework for publishing, deploying, and upgrading Soroban smart contracts. Uses Loam-SDK Publishing Currently smart contracts are insta

null 4 May 10, 2023
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

null 1 Mar 7, 2022
Create your personal token with rust smart contracts

Solana Rust Token ?? This application written Rust using Anchor ⚓

Ritesh 6 Nov 22, 2022
Rust library for build smart contracts on Internet Computer, by the Spinner.Cash team.

Spinner Rust library for building smart contracts on the Internet Computer. More specifically it is used by Spinner.Cash, a decentralized layer-2 prot

Spinner 6 May 31, 2022
Rust implementation for Thippy -- a Substrate parachain for smart contracts.

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

Arthur·Thomas 15 Mar 16, 2022
🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

OKP4 – Open Knowledge Protocol For 6 Nov 17, 2022
Smart contracts for Ref Finance

Ref Finance Contracts This mono repo contains the source code for the smart contracts of Ref Finance on NEAR. Contracts Contract Reference Description

Ref Finance 92 Dec 7, 2022
Skyward Finance smart-contracts

Build and Init ./build.sh near dev-deploy res/skyward.was export CONTRACT_ID=skyward.testnet near call $CONTRACT_ID new --account_id=$CONTRACT_ID Regi

Skyward Finance 777 Jan 4, 2023
My code for the terra.academy course on CosmWasm smart contracts

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

Alex Incerti 0 Nov 7, 2021
Smart contracts powering Spectrum Protocol on Terra

Spectrum Core Contracts This monorepository contains the source code for the core smart contracts implementing Spectrum Protocol on the Terra blockcha

Spectrum Protocol 38 Dec 19, 2022
This is a node implementation of Thippy, a Substrate parachain for smart contracts

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

Arthur·Thomas 15 Mar 16, 2022
CLI for Stellar Smart Contracts.

stellar-contract-cli CLI for running Stellar contracts locally in a test VM. Executes WASM files built using the rs-stellar-contract-sdk. Install carg

Stellar 22 Dec 20, 2022