-
Notifications
You must be signed in to change notification settings - Fork 212
/
deploy.js
64 lines (48 loc) · 1.85 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { CodePromise, Abi, ContractPromise } from '@polkadot/api-contract';
import { ApiPromise, WsProvider, Keyring} from '@polkadot/api';
// import .contract file as json string
import { json } from "./abi.js"
try {
let address; // variable for storing the address of the deployed contract
// API creation for connection to the chain
const wsProvider = new WsProvider('wss://wss-testnet.5ire.network/');
const api = await ApiPromise.create({ provider: wsProvider });
// convert json into usable contract ABI
let contractAbi = new Abi(json, api?.registry?.getChainProperties());
// instantiating wasm blob on the blockchain
const code = new CodePromise(api, json, json.source.wasm);
// gas limit for deployment
const gasLimit = 100000n * 1000000n
// endowment
const value = 0;
// adding fire account for paying the gas fee
const PHRASE = 'negative cheap cherry uncover absurd angle swarm armor tuna lounge hurdle lawsuit';
const keyring = new Keyring({ type: "ed25519" });
const userKeyring = keyring.addFromMnemonic(PHRASE);
// parameters for constructor function inside the contract
// Constructor New
let constructorIndex = 0;
try {
// upload wasm blob
let newMethod = code && contractAbi?.constructors[constructorIndex]?.method
? code.tx[contractAbi.constructors[constructorIndex].method]({
gasLimit: gasLimit,
storageDepositLimit: null,
value: value
})
: null;
// code deploy
const unsub = await newMethod.signAndSend(userKeyring, async (response) => {
if (response.status.isInBlock || response.status.isFinalized) {
address = response.contract.address.toString();
console.log("address ====== ", address);
unsub();
}
});
} catch (e) {
console.log("error catch", e);
}
}
catch(err){
console.log("error",err.toString())
}