https://github.com/chainsafe/game-web3gl
https://github.com/chainsafe/game-web3gl
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/chainsafe/game-web3gl
- Owner: ChainSafe
- License: lgpl-3.0
- Created: 2021-05-22T02:29:15.000Z (over 4 years ago)
- Default Branch: 2020
- Last Pushed: 2023-06-12T21:27:32.000Z (over 2 years ago)
- Last Synced: 2025-10-02T02:53:28.047Z (4 months ago)
- Language: JavaScript
- Homepage: https://chainsafe.github.io/game-web3gl/
- Size: 1.77 MB
- Stars: 6
- Watchers: 35
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unity ^2020.1.0 Web3GL Template
## Methods in Browser

Dispay login modal:
```javascript
window.web3gl.connect();
```
Get Network:
```javascript
window.web3gl.networkId;
```
Get Connected Address:
```javascript
window.web3gl.connectAccount;
```
To Send Transaction:
```javascript
const to = "0xdD4c825203f97984e7867F11eeCc813A036089D1";
const value = "12300000000000000";
const gasLimit = "21000"; // gas limit
const gasPrice = "33333333333";
window.web3gl.sendTransaction(to, value, gasLimit, gasPrice);
```
To Interact with Contract:
```javascript
const method = "increment";
const abi = `[ { "inputs": [], "name": "increment", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "x", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" } ]`;
const contract = "0xB6B8bB1e16A6F73f7078108538979336B9B7341C";
const args = "[]";
const value = "0";
const gasLimit = "222222"; // gas limit
const gasPrice = "333333333333";
window.web3gl.sendContract(method, abi, contract, args, value, gasLimit, gasPrice);
```
Add Custom Token Contract:
```javascript
const tokenContract = "0xd8Aa1F592B6f0670176958d93cD0c6D3E2627597";
const tokenSymbol = "PROS";
const decimals = "18";
const tokenImage = "https://www.your_url_path.com/logo.png";
window.web3gl.addTokenFunction(tokenContract,tokenSymbol,decimals,tokenImage);
```
## Enable Torus
In `web3/index.js`
Uncomment
```javascript
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@toruslabs/torus-embed" }));
```
```javascript
const providerOptions = {
torus: {
package: Torus,
}
};
```