@oyunprotocol/casino-contracts v0.1.6-beta.1
Casino Smart Contracts
Getting Started
Installing
Save storage with pnpm. You can also use regular NPM or Yarn.
pnpm install
Deploy contracts
Local Ganache Start local ganache blockchain node.
npm run ganache
Deploy smart contracts
npm run deploy:local
For testing on frontend side see "Testnet Metamask" section.
Private Testnet
The process is the same but first you have to create you own .env.testnet
file.
For test purposes ONLY, you can generate a bip39 mnemonic at https://iancoleman.io/bip39/.
One other option is to export a mnemonic generated by a Testnet dedicated Metamask instance (see Testnet Metamask section). This Metamask account should be considered insecure after any mnemonic export.
The MNEMONIC provided in .env.local
in NOT suitable as it is publicly known.
Once you have the mnemonic, generate the first account and fund it with some testnet ether. (DM Leo).
Setup the .env.testnet
file.
RPC_URL=http://worker-1.vulcan.link:30545
DEPLOY_BEACON_EPOCH_PERIOD=100
DEPLOY_MAX_TABLE_RISK=1000000000000000000
DEPLOY_MAX_TOTAL_RISK=100000000000000000000
DEPLOY_TABLE_FUNDS=10000000000000000000
HD_WALLET_MNEMONIC=YOUR_MNEMONIC
ACCOUNT_ADDRESS=YOUR_ACCOUNT_ADDRESS
npm run deploy:testnet
Mainnet Same as Testnet process. TODO: Look into hardware wallet based deployment.
Testnet Metamask
When testing a React frontend with Metamask, it is recommended to use a separate isolated Metamask to avoid any security/privacy risks. To install Testnet dedicated Metamask, you will need to create a separate Chrome/Brave browser profile (eg. "Testnet" profile). You should use this browser profile and Metamask instance for test purposes ONLY.
Directory Structure
lib
├── abi # abi output from src/
|
├── ethers # ethers contract abstractions codegenned from abis only (no bytecode)
│
├── solidity # the contracts themselves, in .sol form
│
├── truffle # truffle contract abstractions codegenned from abis + bytecode
|
└── web3 # web3 contract abstractions codegenned from abis + bytecode
Usage
These smart contracts can be imported as a dependency in various ways described below.
Solidity
The solidity smart contracts themselves can simply be imported via the solidity
directory of @oyunprotocol/casino-contracts
.
import "@oyunprotocol/casino-contracts/solidity/Example.sol";
Artifacts
JSON artifacts generated by sol-compiler are available under the abi directory.
import ExampleArtifact from '@oyunprotocol/casino-contracts/abi/Example.json';
Ethers
This library ships with ethers
contract factory abstractions generated by typechain. To use these, make sure you have ethers
installed as a dependency:
pnpm install ethers --save
You can then create an ethers contract as follows:
import ExampleEthers from '@oyunprotocol/casino-contracts/ethers/Example';
const example = ExampleEthers.attach(deployed.address).connect(
new ethers.providers.JsonRpcProvider('http://localhost:8545'),
);
This gives a fully typed (if using TypeScript) version of a ethers contract factory. See the ethers documentation on usage.
Truffle
This library ships with @truffle/contract
abstractions of each of our smart contracts. To use these, make sure you have @truffle/contract
as a dependency.
pnpm install @truffle/contract --save
You can then create an truffle contract as follows:
import ExampleTruffle from '@oyunprotocol/casino-contracts/truffle/Example';
const example = await ExampleTruffle.new();
This gives a fully typed (if using TypeScript) version of a truffle contract. See the truffle documentation on usage.
Web3
This library ships with web3-eth-contract
abstractions of each of our smart contracts. To use these, make sure you have web3
and web3-eth-contract
as a dependency.
pnpm install web3 web3-eth-contract --save
You can then create an web3 contract as follows:
import ExampleWeb3 from '@oyunprotocol/casino-contracts/web3/Example';
const example = ExampleWeb3(web3);
This gives a fully typed (if using TypeScript) version of a web3 contract. See the web3 documentation on usage.
Testing
npm run test
Codestyle
npm run lint:fix
Contributing
To contribute code, feel free to fork this repo.
License
2021 Leo Vigna MIT License.
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago