Update dappservices contract by msig
To update the dappservices contract to the mainnet version on kylin, run
cleos -u https://mainnet.eosn.io get code dappservices --wasm -c dappservices.wasm -a dappservices.abi
Take this abi/wasm and put it in a dappservices folder
mkdir dappservices
mv dappservices.abi dappservices
mv dappservices.wasm dappservices
Then use/modify the following scripts to push the code update by msig on Kylin or Mainnet
Kylin
const { Api, JsonRpc, RpcError, Serialize } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util');
const defaultPrivateKey = ""; // natdeveloper
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const rpc = new JsonRpc('https://kylin.eosn.io', { fetch });
const rpc2 = new JsonRpc('http://localhost:8888', { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), abiProvider: rpc2 });
// const api2 = new Api({ rpc2, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const fs = require('fs');
const wasmFilePath = "./dappservices/dappservices.wasm";
const abiFilePath = "./dappservices/dappservices.abi";
const wasmHexString = fs.readFileSync(wasmFilePath).toString('hex');
const buffer = new Serialize.SerialBuffer({
textEncoder: api.textEncoder,
textDecoder: api.textDecoder,
});
let abiJSON = JSON.parse(fs.readFileSync(abiFilePath, 'utf8'));
let abiDefinitions = api.abiTypes.get('abi_def');
abiJSON = abiDefinitions.fields.reduce(
(acc, { name: fieldName }) =>
Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
abiJSON
);
abiDefinitions.serialize(buffer, abiJSON);
const serializedAbiHexString = Buffer.from(buffer.asUint8Array()).toString('hex');
const actions = [
{
account: 'eosio',
name: 'setcode',
authorization: [
{
actor: 'dappservices',
permission: 'active',
},
],
data: {
account: 'dappservices',
code: wasmHexString,
vmtype: 0,
vmversion: 0
},
},
{
account: 'eosio',
name: 'setabi',
authorization: [
{
actor: 'dappservices',
permission: 'active',
},
],
data: {
account: 'dappservices',
abi: serializedAbiHexString,
}
},
{
account: "dappservices",
name: "updinflation",
authorization: [
{
actor: "dappservices",
permission: "active"
}
],
data: {
inflation_per_block: 2.2159110624367184e-9
}
}
];
(async () => {
try {
// console.log(api)
// api.cachedAbis = await api2.getCachedAbi("dappservices");
console.log(api.cachedAbis);
const serialized_actions = await api.serializeActions(actions)
// BUILD THE MULTISIG PROPOSE TRANSACTION
const proposeInput = {
proposer: 'natdeveloper',
proposal_name: 'updinflation',
requested: [{"actor":"dappservices","permission":"active"}],
trx: {
expiration: '2021-07-29T23:11:48',
ref_block_num: 22480,
ref_block_prefix: 3659047377,
max_net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 0,
context_free_actions: [],
actions: serialized_actions,
transaction_extensions: []
}
};
//PROPOSE THE TRANSACTION
const result = await api.transact({
actions: [{
account: 'eosio.msig',
name: 'propose',
authorization: [{
actor: 'natdeveloper',
permission: 'active',
}],
data: proposeInput,
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
broadcast: true,
sign: true
});
}
catch(e) {
console.log(e)
}
})();
Mainnet
const { Api, JsonRpc, RpcError, Serialize } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util');
const defaultPrivateKey = ""; // bob
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const rpc = new JsonRpc('https://mainnet.eosn.io', { fetch });
const rpc2 = new JsonRpc('https://kylin.eosn.io', { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), abiProvider: rpc2 })
const api2 = new Api({ rpc2, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() })
const fs = require('fs')
const wasmFilePath = "./dappservices/dappservices.wasm";
const abiFilePath = "./dappservices/dappservices.abi";
const wasmHexString = fs.readFileSync(wasmFilePath).toString('hex')
const buffer = new Serialize.SerialBuffer({
textEncoder: api.textEncoder,
textDecoder: api.textDecoder,
})
let abiJSON = JSON.parse(fs.readFileSync(abiFilePath, 'utf8'))
let abiDefinitions = api.abiTypes.get('abi_def')
abiJSON = abiDefinitions.fields.reduce(
(acc, { name: fieldName }) =>
Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
abiJSON
)
abiDefinitions.serialize(buffer, abiJSON)
const serializedAbiHexString = Buffer.from(buffer.asUint8Array()).toString('hex')
const actions = [
{
account: 'eosio',
name: 'setcode',
authorization: [
{
actor: 'dappservices',
permission: 'active',
},
],
data: {
account: 'dappservices',
code: wasmHexString,
vmtype: 0,
vmversion: 0
},
},
{
account: 'eosio',
name: 'setabi',
authorization: [
{
actor: 'dappservices',
permission: 'active',
},
],
data: {
account: 'dappservices',
abi: serializedAbiHexString,
}
},
{
account: "dappservices",
name: "updinflation",
authorization: [
{
actor: "dappservices",
permission: "active"
}
],
data: {
inflation_per_block: 2.2159110624367184e-9
}
}
];
(async () => {
try {
// console.log(api)
// api.cachedAbis = await api2.getCachedAbi("dappservices");
console.log(api.cachedAbis);
const serialized_actions = await api.serializeActions(actions)
// BUILD THE MULTISIG PROPOSE TRANSACTION
const proposeInput = {
proposer: 'zlwb4mcq322g',
proposal_name: 'updinflation',
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"}],
trx: {
expiration: '2021-07-29T23:11:48',
ref_block_num: 22480,
ref_block_prefix: 3659047377,
max_net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 604800,
context_free_actions: [],
actions: serialized_actions,
transaction_extensions: []
}
};
//PROPOSE THE TRANSACTION
const result = await api.transact({
actions: [{
account: 'eosio.msig',
name: 'propose',
authorization: [{
actor: 'zlwb4mcq322g',
permission: 'active',
}],
data: proposeInput,
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
broadcast: true,
sign: true
});
}
catch(e) {
console.log(e)
}
})();
Last updated