This is experimental software that wasn't audited. Use it at your own risk.
In order for errors or bugs to be reproducible on any environment, this example uses Docker. Please install docker
and docker-compose
before the start.
Also if you are looking to deploy your contract to non-local testnet or mainnet, you'll need Infura Project ID. You can find a tutorial of how to obtain one here. Once you have one set it as environment variable:
export INFURA_ID=your_infura_id
Or add it directly to docker-compose.yml
file (not recommended).
Clone repository, build and launch docker image:
git clone https://github.com/vykintasmak/vyper-nft-example
cd vyper-nft-example
docker-compose build
docker-compose up -d
To prepare contract for deployment you will need to edit contract variables found in contracts/ERC721_OpenSea.vy
:
self.name = "Another Lootbox"
self.symbol = "LOOTBOX"
self.baseURI = "https://opensea-creatures-api.herokuapp.com/api/creature/"
name
will be used as the OpenSea Collection name. baseURI
is for accessing metadata of each individual NFTs.
This example uses brownie for smart contract development and testing. In order to interact with smart contracts we use brownie CLI:
In order to run tests:
docker-compose exec sandbox bash -c 'brownie test --network development'
To deploy to either a test or main network you'll need a wallet and some ether on that network. Create new wallet for this specific purpose run:
docker-compose exec sandbox bash -c 'brownie accounts generate [your-account-id]'
Please note that your-account-id
will be needed for each interaction with the contract. You can also load an existing account using a private key using this command:
docker-compose exec sandbox bash -c 'brownie accounts new your-account-id'
Read more on Brownie account management here
OpenSea uses Rinkeby testnet so we recommend testing your NFTs on this net as well. In order to get some Eth you'll need to request some from public faucets like this or that.
Once you have enough Eth you can deploy your contract to testnet using a command:
docker-compose exec sandbox bash -c 'brownie run deploy.py main [your-account-id] --network rinkeby'
Command to mint your first NFT:
docker-compose exec sandbox bash -c 'brownie run interact.py mint [contract-address] [your-account-id] [your-account-address] --network rinkeby'
In the command above contract-address
should be replaced with the address of deployed contract, your-account-id
with the ID you created previously and your-account-address
is the ethereum address that should get the minted NFT.
Once it's done you can open this link: https://testnets.opensea.io/assets/[contract-address]/1
after replacing [contract-address]
with your contract address, to view NFT.
To simplify interaction with the contract each external function is accessible through interact.py
. In order to trigger some smart contract function run:
docker-compose exec sandbox bash -c 'brownie run interact.py [functionName] [contract-address] [your-account-id] [additional-variables] --network rinkeby'
Here functionName
corresponds to the same function name as in the contract, for example balanceOf
. contract-address
is the address of previously deployed contract. your-account-id
is the brownie account you are using to interact with the blockchain. additional-variables
can be one or more variables that are required for function execution, for example balanceOf(_owner: address)
requires you to provide the address of the wallet.
The ERC721_OpenSea.vy contract code was originally written by: Ryuya Nakamura (@nrryuya), Thiwakon Mezenen (@ThiwakonPB) and Anutorn Ravisitikiat(BeatMil).
Ping me on Twitter if you have any suggestions or issues.