Update dappservices contract by msig
To update the dappservices contract to the mainnet version on kylin, run
1
cleos -u https://mainnet.eosn.io get code dappservices --wasm -c dappservices.wasm -a dappservices.abi
Copied!
Take this abi/wasm and put it in a dappservices folder
1
mkdir dappservices
2
mv dappservices.abi dappservices
3
mv dappservices.wasm dappservices
Copied!
Then use/modify the following scripts to push the code update by msig on Kylin or Mainnet
Kylin
1
const { Api, JsonRpc, RpcError, Serialize } = require('eosjs');
2
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
3
const fetch = require('node-fetch'); // node only; not needed in browsers
4
const { TextEncoder, TextDecoder } = require('util');
5
​
6
const defaultPrivateKey = ""; // natdeveloper
7
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
8
​
9
const rpc = new JsonRpc('https://kylin.eosn.io', { fetch });
10
const rpc2 = new JsonRpc('http://localhost:8888', { fetch });
11
​
12
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), abiProvider: rpc2 });
13
// const api2 = new Api({ rpc2, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
14
​
15
const fs = require('fs');
16
const wasmFilePath = "./dappservices/dappservices.wasm";
17
const abiFilePath = "./dappservices/dappservices.abi";
18
​
19
const wasmHexString = fs.readFileSync(wasmFilePath).toString('hex');
20
​
21
const buffer = new Serialize.SerialBuffer({
22
textEncoder: api.textEncoder,
23
textDecoder: api.textDecoder,
24
});
25
​
26
let abiJSON = JSON.parse(fs.readFileSync(abiFilePath, 'utf8'));
27
let abiDefinitions = api.abiTypes.get('abi_def');
28
abiJSON = abiDefinitions.fields.reduce(
29
(acc, { name: fieldName }) =>
30
Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
31
abiJSON
32
);
33
abiDefinitions.serialize(buffer, abiJSON);
34
const serializedAbiHexString = Buffer.from(buffer.asUint8Array()).toString('hex');
35
​
36
const actions = [
37
{
38
account: 'eosio',
39
name: 'setcode',
40
authorization: [
41
{
42
actor: 'dappservices',
43
permission: 'active',
44
},
45
],
46
data: {
47
account: 'dappservices',
48
code: wasmHexString,
49
vmtype: 0,
50
vmversion: 0
51
},
52
},
53
{
54
account: 'eosio',
55
name: 'setabi',
56
authorization: [
57
{
58
actor: 'dappservices',
59
permission: 'active',
60
},
61
],
62
data: {
63
account: 'dappservices',
64
abi: serializedAbiHexString,
65
}
66
},
67
{
68
account: "dappservices",
69
name: "updinflation",
70
authorization: [
71
{
72
actor: "dappservices",
73
permission: "active"
74
}
75
],
76
data: {
77
inflation_per_block: 2.2159110624367184e-9
78
}
79
}
80
];
81
​
82
(async () => {
83
try {
84
// console.log(api)
85
// api.cachedAbis = await api2.getCachedAbi("dappservices");
86
console.log(api.cachedAbis);
87
const serialized_actions = await api.serializeActions(actions)
88
​
89
// BUILD THE MULTISIG PROPOSE TRANSACTION
90
const proposeInput = {
91
proposer: 'natdeveloper',
92
proposal_name: 'updinflation',
93
requested: [{"actor":"dappservices","permission":"active"}],
94
trx: {
95
expiration: '2021-07-29T23:11:48',
96
ref_block_num: 22480,
97
ref_block_prefix: 3659047377,
98
max_net_usage_words: 0,
99
max_cpu_usage_ms: 0,
100
delay_sec: 0,
101
context_free_actions: [],
102
actions: serialized_actions,
103
transaction_extensions: []
104
}
105
};
106
​
107
//PROPOSE THE TRANSACTION
108
const result = await api.transact({
109
actions: [{
110
account: 'eosio.msig',
111
name: 'propose',
112
authorization: [{
113
actor: 'natdeveloper',
114
permission: 'active',
115
}],
116
data: proposeInput,
117
}]
118
}, {
119
blocksBehind: 3,
120
expireSeconds: 30,
121
broadcast: true,
122
sign: true
123
});
124
125
}
126
catch(e) {
127
console.log(e)
128
}
129
})();
Copied!
Mainnet
1
const { Api, JsonRpc, RpcError, Serialize } = require('eosjs');
2
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
3
const fetch = require('node-fetch'); // node only; not needed in browsers
4
const { TextEncoder, TextDecoder } = require('util');
5
​
6
const defaultPrivateKey = ""; // bob
7
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
8
​
9
const rpc = new JsonRpc('https://mainnet.eosn.io', { fetch });
10
const rpc2 = new JsonRpc('https://kylin.eosn.io', { fetch });
11
​
12
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), abiProvider: rpc2 })
13
const api2 = new Api({ rpc2, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() })
14
​
15
const fs = require('fs')
16
const wasmFilePath = "./dappservices/dappservices.wasm";
17
const abiFilePath = "./dappservices/dappservices.abi";
18
​
19
const wasmHexString = fs.readFileSync(wasmFilePath).toString('hex')
20
​
21
const buffer = new Serialize.SerialBuffer({
22
textEncoder: api.textEncoder,
23
textDecoder: api.textDecoder,
24
})
25
​
26
let abiJSON = JSON.parse(fs.readFileSync(abiFilePath, 'utf8'))
27
let abiDefinitions = api.abiTypes.get('abi_def')
28
abiJSON = abiDefinitions.fields.reduce(
29
(acc, { name: fieldName }) =>
30
Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
31
abiJSON
32
)
33
abiDefinitions.serialize(buffer, abiJSON)
34
const serializedAbiHexString = Buffer.from(buffer.asUint8Array()).toString('hex')
35
​
36
const actions = [
37
{
38
account: 'eosio',
39
name: 'setcode',
40
authorization: [
41
{
42
actor: 'dappservices',
43
permission: 'active',
44
},
45
],
46
data: {
47
account: 'dappservices',
48
code: wasmHexString,
49
vmtype: 0,
50
vmversion: 0
51
},
52
},
53
{
54
account: 'eosio',
55
name: 'setabi',
56
authorization: [
57
{
58
actor: 'dappservices',
59
permission: 'active',
60
},
61
],
62
data: {
63
account: 'dappservices',
64
abi: serializedAbiHexString,
65
}
66
},
67
{
68
account: "dappservices",
69
name: "updinflation",
70
authorization: [
71
{
72
actor: "dappservices",
73
permission: "active"
74
}
75
],
76
data: {
77
inflation_per_block: 2.2159110624367184e-9
78
}
79
}
80
];
81
​
82
(async () => {
83
try {
84
// console.log(api)
85
// api.cachedAbis = await api2.getCachedAbi("dappservices");
86
console.log(api.cachedAbis);
87
const serialized_actions = await api.serializeActions(actions)
88
​
89
// BUILD THE MULTISIG PROPOSE TRANSACTION
90
const proposeInput = {
91
proposer: 'zlwb4mcq322g',
92
proposal_name: 'updinflation',
93
requested: [{"actor":"cbrftbkrwwbo","permission":"active"},{"actor":"codeguardian","permission":"active"},{"actor":"cryptolions1","permission":"gov"},{"actor":"dappnetworkk","permission":"active"},{"actor":"dappprovider","permission":"active"},{"actor":"doobiegalnew","permission":"active"},{"actor":"eospheredapp","permission":"active"},{"actor":"everythngeos","permission":"active"},{"actor":"igorlseosrio","permission":"guardian"},{"actor":"ihaveadejavu","permission":"active"},{"actor":"investingwad","permission":"active"},{"actor":"kawrrsytrsbq","permission":"active"},{"actor":"kobybenaroya","permission":"active"},{"actor":"larosenonaka","permission":"active"},{"actor":"mithrilalnce","permission":"active"},{"actor":"mwguardian12","permission":"active"},{"actor":"prjyzjtgxuku","permission":"active"},{"actor":"talmuskaleos","permission":"active"},{"actor":"x452ifggq5va","permission":"active"},{"actor":"xhfq33vt3fg2","permission":"active"},{"actor":"zkwshzdsgdiv","permission":"active"}],
94
trx: {
95
expiration: '2021-07-29T23:11:48',
96
ref_block_num: 22480,
97
ref_block_prefix: 3659047377,
98
max_net_usage_words: 0,
99
max_cpu_usage_ms: 0,
100
delay_sec: 604800,
101
context_free_actions: [],
102
actions: serialized_actions,
103
transaction_extensions: []
104
}
105
};
106
​
107
//PROPOSE THE TRANSACTION
108
const result = await api.transact({
109
actions: [{
110
account: 'eosio.msig',
111
name: 'propose',
112
authorization: [{
113
actor: 'zlwb4mcq322g',
114
permission: 'active',
115
}],
116
data: proposeInput,
117
}]
118
}, {
119
blocksBehind: 3,
120
expireSeconds: 30,
121
broadcast: true,
122
sign: true
123
});
124
125
}
126
catch(e) {
127
console.log(e)
128
}
129
})();
Copied!
Last modified 4mo ago
Copy link