const {default:XuperSDK,Endorsement} = require(“@xuperchain/xuper-sdk”)
const node = ‘https://xuper.baidu.com/nodeapi‘;
const chain = ‘xuper’;
const params = {
server: “https://xuper.baidu.com/nodeapi“,
fee: “400”,
endorseServiceCheckAddr: “jknGxa6eyum1JrATWvSJKW3thJ9GKHA9n”,
endorseServiceFeeAddr: “aB2hpHnTBDxko3UoP2BpBZRujwhdcAFoT”
}
const plugins = [
Endorsement({
transfer: params,
makeTransaction: params
})
];
const xsdk = XuperSDK.getInstance({
node,
chain,
env:{
node:{
disableGRPC:true
}
},
plugins
});
const acc = xsdk.import(“安全码”,”开放网络私钥内容”,true)
const contractAccount = “开放网络工作台注册的合约账户”
// evm 合约的 abi 以及 bin。这里只是示例,你可以编写自己的合约,然后编译出 abi 和 bin。
const abi = “[{“inputs”:[],”payable”:false,”stateMutability”:”nonpayable”,”type”:”constructor”},{“constant”:true,”inputs”:[{“internalType”:”string”,”name”:”key”,”type”:”string”}],”name”:”get”,”outputs”:[{“internalType”:”uint256”,”name”:””,”type”:”uint256”}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[],”name”:”getOwner”,”outputs”:[{“internalType”:”address”,”name”:””,”type”:”address”}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[{“internalType”:”string”,”name”:”key”,”type”:”string”}],”name”:”increase”,”outputs”:[],”payable”:true,”stateMutability”:”payable”,”type”:”function”},{“constant”:false,”inputs”:[{“internalType”:”string”,”name”:”a”,”type”:”string”},{“internalType”:”string”,”name”:”b”,”type”:”string”}],”name”:”join”,”outputs”:[{“internalType”:”string”,”name”:”c”,”type”:”string”},{“internalType”:”string”,”name”:”d”,”type”:”string”}],”payable”:false,”stateMutability”:”nonpayable”,”type”:”function”}]”;
const bin = “608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506106ef806100606000396000f3fe60806040526004361061003f5760003560e01c806329803b2114610044578063693ec85e14610288578063893d20e814610364578063ae896c87146103bb575b600080fd5b34801561005057600080fd5b506101a16004803603604081101561006757600080fd5b810190808035906020019064010000000081111561008457600080fd5b82018360208201111561009657600080fd5b803590602001918460018302840111640100000000831117156100b857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561011b57600080fd5b82018360208201111561012d57600080fd5b8035906020019184600183028401116401000000008311171561014f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610476565b604051808060200180602001838103835285818151815260200191508051906020019080838360005b838110156101e55780820151818401526020810190506101ca565b50505050905090810190601f1680156102125780820380516001836020036101000a031916815260200191505b50838103825284818151815260200191508051906020019080838360005b8381101561024b578082015181840152602081019050610230565b50505050905090810190601f1680156102785780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561029457600080fd5b5061034e600480360360208110156102ab57600080fd5b81019080803590602001906401000000008111156102c857600080fd5b8201836020820111156102da57600080fd5b803590602001918460018302840111640100000000831117156102fc57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061049d565b6040518082815260200191505060405180910390f35b34801561037057600080fd5b50610379610510565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610474600480360360208110156103d157600080fd5b81019080803590602001906401000000008111156103ee57600080fd5b82018360208201111561040057600080fd5b8035906020019184600183028401116401000000008311171561042257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610539565b005b606080836002908051906020019061048f929190610615565b508284915091509250929050565b60006001826040518082805190602001908083835b602083106104d557805182526020820191506020810190506020830392506104b2565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020549050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600180826040518082805190602001908083835b60208310610570578051825260208201915060208101905060208303925061054d565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902054016001826040518082805190602001908083835b602083106105db57805182526020820191506020810190506020830392506105b8565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390208190555050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061065657805160ff1916838001178555610684565b82800160010185558215610684579182015b82811115610683578251825591602001919060010190610668565b5b5090506106919190610695565b5090565b6106b791905b808211156106b357600081600090555060010161069b565b5090565b9056fea265627a7a72315820cf953dc1839436e254d5a3c4c228d708600f054f50da1950ddc1960647386ef364736f6c63430005110032”;
// 在部署其他合约时请使用 xsdk.deployContract()
const start = async () => {
try {
const demo = await xsdk.deploySolidityContract(
contractAccount, // 合约账户
‘counter’, // 合约名字
bin, // evm 合约 bin
abi, // evm 合约 abi
“evm”,
{
“creator”: contractAccount // 合约有初始化参数
},
acc
);
const res = await xsdk.postTransaction(demo.transaction);
console.log(demo)
}
catch (e){
console.log(e)
}
};
start()