init
8
Assets/WebGLTemplates/Cronos_Defi_Wallet.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efa5d46c202c97847855392325ca1c93
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/WebGLTemplates/Cronos_Defi_Wallet/README.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# 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);
|
||||
```
|
||||
|
||||
## 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,
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Enable WalletConnect
|
||||
|
||||
In `web3/index.js`
|
||||
|
||||
Uncomment
|
||||
|
||||
```javascript
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@walletconnect/web3-provider@1.2.1/dist/umd/index.min.js" }));
|
||||
```
|
||||
|
||||
```javascript
|
||||
const providerOptions = {
|
||||
walletconnect: {
|
||||
package: window.WalletConnectProvider.default,
|
||||
options: {
|
||||
infuraId: "00000000000000000000000000000000",
|
||||
},
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Replace `infuraId: "00000000000000000000000000000000"`
|
||||
|
||||

|
||||
7
Assets/WebGLTemplates/Cronos_Defi_Wallet/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 462923b12be1bc246828df75d88ae80c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0344eab6c31920498df5c9eaaf2ad55
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4137ee136a0403048af218188e9c0939
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 175 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 376588a0ff7bc634eb690bab5134bc53
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 96 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34fe0d38edf77f94f9f3e2c47bb154ec
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 109 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acf249e7bf9966242bd686c6dc5cc5c3
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 74 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6339b6df07f90640b045e4020723063
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 84 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44a2f417cb63ae84fa1bc2f8a241d974
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
body { padding: 0; margin: 0 }
|
||||
#unity-container { position: absolute }
|
||||
#unity-container.unity-desktop { left: 50%; top: 50%; transform: translate(-50%, -50%) }
|
||||
#unity-container.unity-mobile { width: 100%; height: 100% }
|
||||
#unity-canvas { background: {{{ BACKGROUND_COLOR }}} }
|
||||
.unity-mobile #unity-canvas { width: 100%; height: 100% }
|
||||
#unity-loading-bar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none }
|
||||
#unity-logo { width: 154px; height: 130px; background: url('unity-logo-{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}.png') no-repeat center }
|
||||
#unity-progress-bar-empty { width: 141px; height: 18px; margin-top: 10px; background: url('progress-bar-empty-{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}.png') no-repeat center }
|
||||
#unity-progress-bar-full { width: 0%; height: 18px; margin-top: 10px; background: url('progress-bar-full-{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}.png') no-repeat center }
|
||||
#unity-footer { position: relative }
|
||||
.unity-mobile #unity-footer { display: none }
|
||||
#unity-webgl-logo { float:left; width: 204px; height: 38px; background: url('webgl-logo.png') no-repeat center }
|
||||
#unity-build-title { float: right; margin-right: 10px; line-height: 38px; font-family: arial; font-size: 18px }
|
||||
#unity-fullscreen-button { float: right; width: 38px; height: 38px; background: url('fullscreen-button.png') no-repeat center }
|
||||
#unity-warning { position: absolute; left: 50%; top: 5%; transform: translate(-50%); background: white; padding: 10px; display: none }
|
||||
.web3modal-modal-card { font-family: sans-serif}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5db486dc38d7a54c9b1ace35044ab6c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b3d15ba34de1354481693e65eec4ec3
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5eba1d9664fb8d84b8991e9a8a283a46
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e38abb20bc9c7be48b0002e37ecd89ce
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
117
Assets/WebGLTemplates/Cronos_Defi_Wallet/index.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Unity WebGL Player | {{{ PRODUCT_NAME }}}</title>
|
||||
<link rel="shortcut icon" href="TemplateData/favicon.ico">
|
||||
<link rel="stylesheet" href="TemplateData/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="unity-container" class="unity-desktop">
|
||||
<canvas id="unity-canvas" width={{{ WIDTH }}} height={{{ HEIGHT }}}></canvas>
|
||||
<div id="unity-loading-bar">
|
||||
<div id="unity-logo"></div>
|
||||
<div id="unity-progress-bar-empty">
|
||||
<div id="unity-progress-bar-full"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="unity-warning"> </div>
|
||||
<div id="unity-footer">
|
||||
<div id="unity-webgl-logo"></div>
|
||||
<div id="unity-fullscreen-button"></div>
|
||||
<div id="unity-build-title">{{{ PRODUCT_NAME }}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="web3/index.js"></script>
|
||||
<script>
|
||||
var container = document.querySelector("#unity-container");
|
||||
var canvas = document.querySelector("#unity-canvas");
|
||||
var loadingBar = document.querySelector("#unity-loading-bar");
|
||||
var progressBarFull = document.querySelector("#unity-progress-bar-full");
|
||||
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
|
||||
var warningBanner = document.querySelector("#unity-warning");
|
||||
|
||||
// Shows a temporary message banner/ribbon for a few seconds, or
|
||||
// a permanent error message on top of the canvas if type=='error'.
|
||||
// If type=='warning', a yellow highlight color is used.
|
||||
// Modify or remove this function to customize the visually presented
|
||||
// way that non-critical warnings and error messages are presented to the
|
||||
// user.
|
||||
function unityShowBanner(msg, type) {
|
||||
function updateBannerVisibility() {
|
||||
warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
|
||||
}
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = msg;
|
||||
warningBanner.appendChild(div);
|
||||
if (type == 'error') div.style = 'background: red; padding: 10px;';
|
||||
else {
|
||||
if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
|
||||
setTimeout(function() {
|
||||
warningBanner.removeChild(div);
|
||||
updateBannerVisibility();
|
||||
}, 5000);
|
||||
}
|
||||
updateBannerVisibility();
|
||||
}
|
||||
|
||||
var buildUrl = "Build";
|
||||
var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
|
||||
var config = {
|
||||
dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
|
||||
frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
|
||||
codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
|
||||
#if MEMORY_FILENAME
|
||||
memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
|
||||
#endif
|
||||
#if SYMBOLS_FILENAME
|
||||
symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
|
||||
#endif
|
||||
streamingAssetsUrl: "StreamingAssets",
|
||||
companyName: "{{{ COMPANY_NAME }}}",
|
||||
productName: "{{{ PRODUCT_NAME }}}",
|
||||
productVersion: "{{{ PRODUCT_VERSION }}}",
|
||||
showBanner: unityShowBanner,
|
||||
};
|
||||
|
||||
// By default Unity keeps WebGL canvas render target size matched with
|
||||
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
|
||||
// Set this to false if you want to decouple this synchronization from
|
||||
// happening inside the engine, and you would instead like to size up
|
||||
// the canvas DOM size and WebGL render target sizes yourself.
|
||||
// config.matchWebGLToCanvasSize = false;
|
||||
|
||||
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
|
||||
container.className = "unity-mobile";
|
||||
// Avoid draining fillrate performance on mobile devices,
|
||||
// and default/override low DPI mode on mobile browsers.
|
||||
config.devicePixelRatio = 1;
|
||||
unityShowBanner('WebGL builds are not supported on mobile devices.');
|
||||
} else {
|
||||
canvas.style.width = "{{{ WIDTH }}}px";
|
||||
canvas.style.height = "{{{ HEIGHT }}}px";
|
||||
}
|
||||
#if BACKGROUND_FILENAME
|
||||
canvas.style.background = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
|
||||
#endif
|
||||
loadingBar.style.display = "block";
|
||||
|
||||
var script = document.createElement("script");
|
||||
script.src = loaderUrl;
|
||||
script.onload = () => {
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
progressBarFull.style.width = 100 * progress + "%";
|
||||
}).then((unityInstance) => {
|
||||
loadingBar.style.display = "none";
|
||||
fullscreenButton.onclick = () => {
|
||||
unityInstance.SetFullscreen(1);
|
||||
};
|
||||
}).catch((message) => {
|
||||
alert(message);
|
||||
});
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
7
Assets/WebGLTemplates/Cronos_Defi_Wallet/index.html.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af795533b2381fd4d82a55922e6e8cae
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/WebGLTemplates/Cronos_Defi_Wallet/network.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Used to set the network: https://chainlist.org/
|
||||
1 Mainnet
|
||||
3 Ropsten
|
||||
4 Rinkeby
|
||||
5 Goerli
|
||||
42 Kovan
|
||||
56 Binance Smart Chain Mainnet
|
||||
97 Binance Smart Chain Testnet
|
||||
100 xDai
|
||||
137 Matic
|
||||
1287 Moonbase Testnet
|
||||
80001 Matic Testnet
|
||||
43113 Avalanche Testnet
|
||||
43114 Avalanche Mainnet
|
||||
42220 Celo Mainnet
|
||||
44787 Celo Alfajores Testnet
|
||||
62320 Celo Baklava Testnet
|
||||
1666700000 Harmony Testnet Shard0
|
||||
1666600000 Harmony Mainnet Shard0
|
||||
25 Cronos Mainnet Beta
|
||||
338 Cronos Testnet
|
||||
*/
|
||||
|
||||
window.web3ChainId = 1;
|
||||
7
Assets/WebGLTemplates/Cronos_Defi_Wallet/network.js.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2da1890fc862094d9bc601c22ac0ede
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/WebGLTemplates/Cronos_Defi_Wallet/thumbnail.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82b3c535062d18344abe027de5734d79
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebGLTemplates/Cronos_Defi_Wallet/web3.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48a280fdc19dddd41accb79c15508141
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
275
Assets/WebGLTemplates/Cronos_Defi_Wallet/web3/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c27244ce0cbde34db841323bce1b140
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebGLTemplates/Cronos_Defi_Wallet/web3/lib.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 490050520cdc57f489ef9dfd7d611338
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/WebGLTemplates/Cronos_Defi_Wallet/web3/lib/web3.min.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0c33c2497db0f347bef648e99d81974
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bed197276704794585bd3ebb4b4b5c9
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebGLTemplates/Web3GL-2020x.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bb443cf7f2936149b7fc4e444cc0f9d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
165
Assets/WebGLTemplates/Web3GL-2020x/LICENSE
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
7
Assets/WebGLTemplates/Web3GL-2020x/LICENSE.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bc7442fa92bd82469fffe2cdff20945
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/WebGLTemplates/Web3GL-2020x/README.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# 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);
|
||||
```
|
||||
|
||||
## 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,
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Enable WalletConnect
|
||||
|
||||
In `web3/index.js`
|
||||
|
||||
Uncomment
|
||||
|
||||
```javascript
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@walletconnect/web3-provider@1.2.1/dist/umd/index.min.js" }));
|
||||
```
|
||||
|
||||
```javascript
|
||||
const providerOptions = {
|
||||
walletconnect: {
|
||||
package: window.WalletConnectProvider.default,
|
||||
options: {
|
||||
infuraId: "00000000000000000000000000000000",
|
||||
},
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Replace `infuraId: "00000000000000000000000000000000"`
|
||||
|
||||

|
||||
7
Assets/WebGLTemplates/Web3GL-2020x/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 829fce0d7ef7c25439678127ee7e5d59
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebGLTemplates/Web3GL-2020x/TemplateData.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 281e0a1fe85466842921663f31625fea
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/WebGLTemplates/Web3GL-2020x/TemplateData/favicon.ico
Normal file
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 385301c25513b104eb56716fee71716d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 175 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d5e201eebea6c84f8bd5b2588272cec
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 96 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b285cac0ffc78c45bd85800e265960e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 109 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81e504b02493e2d489a5f7873e562677
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 74 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f790f16d39788f4bab1cc9541b8be4f
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 84 B |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddba6bb134c3c5d4f9013ab3e954a083
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/WebGLTemplates/Web3GL-2020x/TemplateData/style.css
Normal file
@@ -0,0 +1,17 @@
|
||||
body { padding: 0; margin: 0 }
|
||||
#unity-container { position: absolute }
|
||||
#unity-container.unity-desktop { left: 50%; top: 50%; transform: translate(-50%, -50%) }
|
||||
#unity-container.unity-mobile { width: 100%; height: 100% }
|
||||
#unity-canvas { background: {{{ BACKGROUND_COLOR }}} }
|
||||
.unity-mobile #unity-canvas { width: 100%; height: 100% }
|
||||
#unity-loading-bar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none }
|
||||
#unity-logo { width: 154px; height: 130px; background: url('unity-logo-{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}.png') no-repeat center }
|
||||
#unity-progress-bar-empty { width: 141px; height: 18px; margin-top: 10px; background: url('progress-bar-empty-{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}.png') no-repeat center }
|
||||
#unity-progress-bar-full { width: 0%; height: 18px; margin-top: 10px; background: url('progress-bar-full-{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}.png') no-repeat center }
|
||||
#unity-footer { position: relative }
|
||||
.unity-mobile #unity-footer { display: none }
|
||||
#unity-webgl-logo { float:left; width: 204px; height: 38px; background: url('webgl-logo.png') no-repeat center }
|
||||
#unity-build-title { float: right; margin-right: 10px; line-height: 38px; font-family: arial; font-size: 18px }
|
||||
#unity-fullscreen-button { float: right; width: 38px; height: 38px; background: url('fullscreen-button.png') no-repeat center }
|
||||
#unity-warning { position: absolute; left: 50%; top: 5%; transform: translate(-50%); background: white; padding: 10px; display: none }
|
||||
.web3modal-modal-card { font-family: sans-serif}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3864d184dd8bdb5478c7c1f749f3e79b
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd8cc130a5979ed40a6bbdc53fbfd83e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b40a874905262444a6853092df97661
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/WebGLTemplates/Web3GL-2020x/TemplateData/webgl-logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c314a9a52fd626a499860af88dab9d1c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
117
Assets/WebGLTemplates/Web3GL-2020x/index.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Unity WebGL Player | {{{ PRODUCT_NAME }}}</title>
|
||||
<link rel="shortcut icon" href="TemplateData/favicon.ico">
|
||||
<link rel="stylesheet" href="TemplateData/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="unity-container" class="unity-desktop">
|
||||
<canvas id="unity-canvas" width={{{ WIDTH }}} height={{{ HEIGHT }}}></canvas>
|
||||
<div id="unity-loading-bar">
|
||||
<div id="unity-logo"></div>
|
||||
<div id="unity-progress-bar-empty">
|
||||
<div id="unity-progress-bar-full"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="unity-warning"> </div>
|
||||
<div id="unity-footer">
|
||||
<div id="unity-webgl-logo"></div>
|
||||
<div id="unity-fullscreen-button"></div>
|
||||
<div id="unity-build-title">{{{ PRODUCT_NAME }}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="web3/index.js"></script>
|
||||
<script>
|
||||
var container = document.querySelector("#unity-container");
|
||||
var canvas = document.querySelector("#unity-canvas");
|
||||
var loadingBar = document.querySelector("#unity-loading-bar");
|
||||
var progressBarFull = document.querySelector("#unity-progress-bar-full");
|
||||
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
|
||||
var warningBanner = document.querySelector("#unity-warning");
|
||||
|
||||
// Shows a temporary message banner/ribbon for a few seconds, or
|
||||
// a permanent error message on top of the canvas if type=='error'.
|
||||
// If type=='warning', a yellow highlight color is used.
|
||||
// Modify or remove this function to customize the visually presented
|
||||
// way that non-critical warnings and error messages are presented to the
|
||||
// user.
|
||||
function unityShowBanner(msg, type) {
|
||||
function updateBannerVisibility() {
|
||||
warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
|
||||
}
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = msg;
|
||||
warningBanner.appendChild(div);
|
||||
if (type == 'error') div.style = 'background: red; padding: 10px;';
|
||||
else {
|
||||
if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
|
||||
setTimeout(function() {
|
||||
warningBanner.removeChild(div);
|
||||
updateBannerVisibility();
|
||||
}, 5000);
|
||||
}
|
||||
updateBannerVisibility();
|
||||
}
|
||||
|
||||
var buildUrl = "Build";
|
||||
var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
|
||||
var config = {
|
||||
dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
|
||||
frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
|
||||
codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
|
||||
#if MEMORY_FILENAME
|
||||
memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
|
||||
#endif
|
||||
#if SYMBOLS_FILENAME
|
||||
symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
|
||||
#endif
|
||||
streamingAssetsUrl: "StreamingAssets",
|
||||
companyName: "{{{ COMPANY_NAME }}}",
|
||||
productName: "{{{ PRODUCT_NAME }}}",
|
||||
productVersion: "{{{ PRODUCT_VERSION }}}",
|
||||
showBanner: unityShowBanner,
|
||||
};
|
||||
|
||||
// By default Unity keeps WebGL canvas render target size matched with
|
||||
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
|
||||
// Set this to false if you want to decouple this synchronization from
|
||||
// happening inside the engine, and you would instead like to size up
|
||||
// the canvas DOM size and WebGL render target sizes yourself.
|
||||
// config.matchWebGLToCanvasSize = false;
|
||||
|
||||
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
|
||||
container.className = "unity-mobile";
|
||||
// Avoid draining fillrate performance on mobile devices,
|
||||
// and default/override low DPI mode on mobile browsers.
|
||||
config.devicePixelRatio = 1;
|
||||
unityShowBanner('WebGL builds are not supported on mobile devices.');
|
||||
} else {
|
||||
canvas.style.width = "{{{ WIDTH }}}px";
|
||||
canvas.style.height = "{{{ HEIGHT }}}px";
|
||||
}
|
||||
#if BACKGROUND_FILENAME
|
||||
canvas.style.background = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
|
||||
#endif
|
||||
loadingBar.style.display = "block";
|
||||
|
||||
var script = document.createElement("script");
|
||||
script.src = loaderUrl;
|
||||
script.onload = () => {
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
progressBarFull.style.width = 100 * progress + "%";
|
||||
}).then((unityInstance) => {
|
||||
loadingBar.style.display = "none";
|
||||
fullscreenButton.onclick = () => {
|
||||
unityInstance.SetFullscreen(1);
|
||||
};
|
||||
}).catch((message) => {
|
||||
alert(message);
|
||||
});
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
7
Assets/WebGLTemplates/Web3GL-2020x/index.html.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea22ab2745416cd439b79292e4ef7d3b
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/WebGLTemplates/Web3GL-2020x/network.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Used to set the network: https://chainlist.org/
|
||||
1 Mainnet
|
||||
3 Ropsten
|
||||
4 Rinkeby
|
||||
5 Goerli
|
||||
42 Kovan
|
||||
56 Binance Smart Chain Mainnet
|
||||
97 Binance Smart Chain Testnet
|
||||
100 xDai
|
||||
137 Matic
|
||||
1287 Moonbase Testnet
|
||||
80001 Matic Testnet
|
||||
43113 Avalanche Testnet
|
||||
43114 Avalanche Mainnet
|
||||
42220 Celo Mainnet
|
||||
44787 Celo Alfajores Testnet
|
||||
62320 Celo Baklava Testnet
|
||||
1666700000 Harmony Testnet Shard0
|
||||
1666600000 Harmony Mainnet Shard0
|
||||
25 Cronos Mainnet Beta
|
||||
338 Cronos Testnet
|
||||
*/
|
||||
|
||||
window.web3ChainId = 97;
|
||||
7
Assets/WebGLTemplates/Web3GL-2020x/network.js.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccbc3f2bf15d512448b2065530f7f02c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/WebGLTemplates/Web3GL-2020x/thumbnail.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
7
Assets/WebGLTemplates/Web3GL-2020x/thumbnail.png.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ec4e1d3604819a469ae3c3feaf257cf
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebGLTemplates/Web3GL-2020x/web3.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c7cdd4dd7203184fb2ebc41e89a4fdf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
270
Assets/WebGLTemplates/Web3GL-2020x/web3/index.js
Normal file
@@ -0,0 +1,270 @@
|
||||
// load network.js to get network/chain id
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "./network.js" }));
|
||||
// load web3modal to connect to wallet
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "./web3/lib/web3modal.js" }));
|
||||
// load web3js to create transactions
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "./web3/lib/web3.min.js" }));
|
||||
|
||||
// uncomment to enable torus wallet
|
||||
// document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@toruslabs/torus-embed" }));
|
||||
// uncomment to enable walletconnect
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@walletconnect/web3-provider@1.8.0/dist/umd/index.min.js" }));
|
||||
|
||||
// load web3gl to connect to unity
|
||||
window.web3gl = {
|
||||
networkId: 0,
|
||||
connect,
|
||||
connectAccount: "",
|
||||
signMessage,
|
||||
signMessageResponse: "",
|
||||
callContract,
|
||||
callContractResponse:"",
|
||||
callContractError:"",
|
||||
sendTransaction,
|
||||
sendTransactionResponse: "",
|
||||
sha3Message,
|
||||
hashMessageResponse: "",
|
||||
ecRecover,
|
||||
ecRecoverAddressResponse:"",
|
||||
sendTransactionResponse: "",
|
||||
sendTransactionData,
|
||||
sendTransactionResponseData:"",
|
||||
sendContract,
|
||||
sendContractResponse: "",
|
||||
};
|
||||
|
||||
// will be defined after connect()
|
||||
let provider;
|
||||
let web3;
|
||||
|
||||
/*
|
||||
paste this in inspector to connect to wallet:
|
||||
window.web3gl.connect()
|
||||
*/
|
||||
async function connect() {
|
||||
// uncomment to enable torus and walletconnect
|
||||
const providerOptions = {
|
||||
// torus: {
|
||||
// package: Torus,
|
||||
// },
|
||||
// walletconnect: {
|
||||
// package: window.WalletConnectProvider.default,
|
||||
// options: {
|
||||
// infuraId: "00000000000000000000000000000000",
|
||||
// },
|
||||
// },
|
||||
};
|
||||
|
||||
const web3Modal = new window.Web3Modal.default({
|
||||
providerOptions,
|
||||
});
|
||||
|
||||
web3Modal.clearCachedProvider();
|
||||
|
||||
// set provider
|
||||
provider = await web3Modal.connect();
|
||||
web3 = new Web3(provider);
|
||||
|
||||
// set current network id
|
||||
web3gl.networkId = parseInt(provider.chainId);
|
||||
|
||||
// if current network id is not equal to network id, then switch
|
||||
if (web3gl.networkId != window.web3ChainId) {
|
||||
try {
|
||||
await window.ethereum.request({
|
||||
method: "wallet_switchEthereumChain",
|
||||
params: [{ chainId: `0x${window.web3ChainId.toString(16)}` }], // chainId must be in hexadecimal numbers
|
||||
});
|
||||
} catch {
|
||||
// if network isn't added, pop-up metamask to add
|
||||
await addEthereumChain();
|
||||
}
|
||||
}
|
||||
|
||||
// set current account
|
||||
// provider.selectedAddress works for metamask and torus
|
||||
// provider.accounts[0] works for walletconnect
|
||||
web3gl.connectAccount = provider.selectedAddress || provider.accounts[0];
|
||||
|
||||
// refresh page if player changes account
|
||||
provider.on("accountsChanged", (accounts) => {
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
// update if player changes network
|
||||
provider.on("chainChanged", (chainId) => {
|
||||
web3gl.networkId = parseInt(chainId);
|
||||
});
|
||||
}
|
||||
/*
|
||||
Will calculate the sha3 of the input.
|
||||
*/
|
||||
async function sha3Message(message) {
|
||||
try {
|
||||
const hashedMessage = await web3.utils.sha3(message);
|
||||
window.web3gl.hashMessageResponse = hashedMessage;
|
||||
} catch (error) {
|
||||
window.web3gl.hashMessageResponse = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Will recover the address of signer
|
||||
*/
|
||||
async function ecRecover(message,signature) {
|
||||
try {
|
||||
const recoverAddress = await web3.eth.accounts.recover(message, signature);
|
||||
window.web3gl.ecRecoverAddressResponse = recoverAddress;
|
||||
} catch (error) {
|
||||
window.web3gl.ecRecoverAddressResponse = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
paste this in inspector to connect to sign message:
|
||||
window.web3gl.signMessage("hello")
|
||||
*/
|
||||
async function signMessage(message) {
|
||||
try {
|
||||
const from = (await web3.eth.getAccounts())[0];
|
||||
const signature = await web3.eth.personal.sign(message, from, "");
|
||||
console.log(signature);
|
||||
window.web3gl.signMessageResponse = signature;
|
||||
} catch (error) {
|
||||
window.web3gl.signMessageResponse = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
paste this in inspector to send eth:
|
||||
const to = "0xdD4c825203f97984e7867F11eeCc813A036089D1"
|
||||
const value = "12300000000000000"
|
||||
const gasLimit = "21000" // gas limit
|
||||
const gasPrice = "33333333333"
|
||||
window.web3gl.sendTransaction(to, value, gasLimit, gasPrice);
|
||||
*/
|
||||
async function sendTransaction(to, value, gasLimit, gasPrice) {
|
||||
const from = (await web3.eth.getAccounts())[0];
|
||||
web3.eth
|
||||
.sendTransaction({
|
||||
from,
|
||||
to,
|
||||
value,
|
||||
gas: gasLimit ? gasLimit : undefined,
|
||||
gasPrice: gasPrice ? gasPrice : undefined,
|
||||
})
|
||||
.on("transactionHash", (transactionHash) => {
|
||||
window.web3gl.sendTransactionResponse = transactionHash;
|
||||
})
|
||||
.on("error", (error) => {
|
||||
window.web3gl.sendTransactionResponse = error.message;
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
paste this in inspector to send eth:
|
||||
const to = "0x20E7D0C4182149ADBeFE446E82358A2b2D5244e9"
|
||||
const value = "0"
|
||||
const gasPrice = "1100000010"
|
||||
const gasLimit = "228620" // gas limit
|
||||
const data = "0xd0def521000000000000000000000000d25b827d92b0fd656a1c829933e9b0b836d5c3e20000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002e516d586a576a6a4d55387233395543455a38343833614e6564774e5246524c767656396b7771314770436774686a000000000000000000000000000000000000"
|
||||
window.web3gl.sendTransactionData(to, value, gasPrice, gasLimit, data);
|
||||
*/
|
||||
async function sendTransactionData(to, value, gasPrice, gasLimit, data) {
|
||||
const from = (await web3.eth.getAccounts())[0];
|
||||
web3.eth
|
||||
.sendTransaction({
|
||||
from,
|
||||
to,
|
||||
value,
|
||||
gasPrice: gasPrice ? gasPrice : undefined,
|
||||
gas: gasLimit ? gasLimit : undefined,
|
||||
data: data ? data : undefined,
|
||||
})
|
||||
.on("transactionHash", (transactionHash) => {
|
||||
window.web3gl.sendTransactionResponseData = transactionHash;
|
||||
})
|
||||
.on("error", (error) => {
|
||||
window.web3gl.sendTransactionResponseData = error.message;
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
calls a non-mutable contract method.
|
||||
const method = "x"
|
||||
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 = "[]"
|
||||
window.web3gl.callContract(method, abi, contract, args)
|
||||
*/
|
||||
async function callContract(method, abi, contract, args) {
|
||||
const from = (await web3.eth.getAccounts())[0];
|
||||
new web3.eth.Contract(JSON.parse(abi), contract).methods[method](
|
||||
...JSON.parse(args)
|
||||
).call()
|
||||
.then((result) => window.web3gl.callContractResponse = result)
|
||||
.catch((error) => window.web3gl.callContractError = error.message);
|
||||
}
|
||||
|
||||
/*
|
||||
paste this in inspector to connect to interact with contract:
|
||||
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)
|
||||
*/
|
||||
async function sendContract(method, abi, contract, args, value, gasLimit, gasPrice) {
|
||||
const from = (await web3.eth.getAccounts())[0];
|
||||
new web3.eth.Contract(JSON.parse(abi), contract).methods[method](...JSON.parse(args))
|
||||
.send({
|
||||
from,
|
||||
value,
|
||||
gas: gasLimit ? gasLimit : undefined,
|
||||
gasPrice: gasPrice ? gasPrice : undefined,
|
||||
})
|
||||
.on("transactionHash", (transactionHash) => {
|
||||
window.web3gl.sendContractResponse = transactionHash;
|
||||
})
|
||||
.on("error", (error) => {
|
||||
window.web3gl.sendContractResponse = error.message;
|
||||
});
|
||||
}
|
||||
|
||||
// add new wallet to in metamask
|
||||
async function addEthereumChain() {
|
||||
const account = (await web3.eth.getAccounts())[0];
|
||||
|
||||
// fetch https://chainid.network/chains.json
|
||||
const response = await fetch("https://chainid.network/chains.json");
|
||||
const chains = await response.json();
|
||||
|
||||
// find chain with network id
|
||||
const chain = chains.find((chain) => chain.chainId == window.web3ChainId);
|
||||
|
||||
const params = {
|
||||
chainId: "0x" + chain.chainId.toString(16), // A 0x-prefixed hexadecimal string
|
||||
chainName: chain.name,
|
||||
nativeCurrency: {
|
||||
name: chain.nativeCurrency.name,
|
||||
symbol: chain.nativeCurrency.symbol, // 2-6 characters long
|
||||
decimals: chain.nativeCurrency.decimals,
|
||||
},
|
||||
rpcUrls: chain.rpc,
|
||||
blockExplorerUrls: [chain.explorers && chain.explorers.length > 0 && chain.explorers[0].url ? chain.explorers[0].url : chain.infoURL],
|
||||
};
|
||||
|
||||
await window.ethereum
|
||||
.request({
|
||||
method: "wallet_addEthereumChain",
|
||||
params: [params, account],
|
||||
})
|
||||
.catch(() => {
|
||||
// I give up
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
7
Assets/WebGLTemplates/Web3GL-2020x/web3/index.js.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c89fc107d8f5bd34082b02f2ae428517
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/WebGLTemplates/Web3GL-2020x/web3/lib.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60c0ea2d870f852479950d43a1b0688d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/WebGLTemplates/Web3GL-2020x/web3/lib/web3.min.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec93bc25778489744a13ab7d5dc2967a
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/WebGLTemplates/Web3GL-2020x/web3/lib/web3modal.js
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cf3db3f31c1ef84daf1fc398e46e26b
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
95
Assets/WebGLTemplates/Web3GL-2020x/web3/light.js
Normal file
@@ -0,0 +1,95 @@
|
||||
// load network.js to get network/chain id
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "./network.js" }));
|
||||
// load web3modal to connect to wallet
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "./web3/lib/web3modal.js" }));
|
||||
// load web3js to create transactions
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "./web3/lib/web3.min.js" }));
|
||||
// uncomment to enable torus wallet
|
||||
// document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@toruslabs/torus-embed" }));
|
||||
// uncomment to enable walletconnect
|
||||
document.body.appendChild(Object.assign(document.createElement("script"), { type: "text/javascript", src: "https://unpkg.com/@walletconnect/web3-provider@1.2.1/dist/umd/index.min.js" }));
|
||||
|
||||
// load web3gl to connect to unity
|
||||
window.web3gl = {
|
||||
networkId: 0,
|
||||
connect,
|
||||
connectAccount: "",
|
||||
clearResponse,
|
||||
sendAsync,
|
||||
sendAsyncResponse: "",
|
||||
sendAsyncError: "",
|
||||
};
|
||||
|
||||
// will be defined after connect()
|
||||
let provider;
|
||||
let web3;
|
||||
|
||||
/*
|
||||
paste this in inspector to connect to wallet:
|
||||
window.web3gl.connect()
|
||||
*/
|
||||
async function connect() {
|
||||
// uncomment to enable torus
|
||||
const providerOptions = {
|
||||
// torus: {
|
||||
// package: Torus,
|
||||
// },
|
||||
};
|
||||
|
||||
if (window.web3InfuraId !== undefined && window.web3InfuraId !== "" && window.web3InfuraId !== "00000000000000000000000000000000") {
|
||||
providerOptions.walletconnect = {
|
||||
package: window.WalletConnectProvider.default,
|
||||
options: {
|
||||
infuraId: window.web3InfuraId
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const web3Modal = new window.Web3Modal.default({
|
||||
providerOptions,
|
||||
});
|
||||
|
||||
web3Modal.clearCachedProvider();
|
||||
|
||||
// set provider
|
||||
provider = await web3Modal.connect();
|
||||
web3 = new Web3(provider);
|
||||
|
||||
// set current account
|
||||
// provider.selectedAddress works for metamask and torus
|
||||
// provider.accounts[0] works for walletconnect
|
||||
web3gl.connectAccount = provider.selectedAddress || provider.accounts[0];
|
||||
|
||||
// refresh page if player changes account
|
||||
provider.on("accountsChanged", (accounts) => {
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
// update if player changes network
|
||||
provider.on("chainChanged", (chainId) => {
|
||||
web3gl.networkId = parseInt(chainId);
|
||||
});
|
||||
}
|
||||
|
||||
function clearResponse() {
|
||||
window.web3gl.sendAsyncResponse = "";
|
||||
window.web3gl.sendAsyncError = "";
|
||||
}
|
||||
|
||||
async function sendAsync(method, params) {
|
||||
web3.currentProvider.sendAsync(
|
||||
{
|
||||
jsonrpc: "2.0",
|
||||
method: method,
|
||||
params: JSON.parse(params),
|
||||
id: new Date().getTime(),
|
||||
},
|
||||
async (error, result) => {
|
||||
if (error) {
|
||||
window.web3gl.sendAsyncError = JSON.stringify(error);
|
||||
} else {
|
||||
window.web3gl.sendAsyncResponse = JSON.stringify(result.result);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
7
Assets/WebGLTemplates/Web3GL-2020x/web3/light.js.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef430930af2945eb9f9b9f40e04871c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1
Assets/WebGLTemplates/Web3GL-2020x/web3/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"additionalFiles":["ipfs://QmesrwJc77EEvYs3Tvm8UJ2EzbKhtikGYSft6AqAGTapt5"],"description":"11-2022 Chainsafe Skale Gaming Community Call Limited Edition NFT","image":"ipfs://Qmc8mZcqTuFRrsQ6Hra6KrFgeyboxtFpNZPj4EEo6635pS","name":"NFT 2 Community Call"}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a9cceee0b7042344ac66ff04d1ede4f
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||