Einen nützlichen Solidity
Vertrag finden Sie HIER . Zum Zeitpunkt der Bereitstellung gibt es jedoch zwei Dinge:
(1) Das erste ist der contract balance
da sein constructor
payable
. (2) Und der zweite ist der constructor's parameters value
des constructor's parameters value
( (address **_recipient**, uint256 **duration**)
)
Um einen Vertrag web3.js 1.0.0-beta.34
ich web3.js 1.0.0-beta.34
. Hier sind die Schritte, die ich zum Bereitstellen dieses Vertrags ausführe:
Web3 = require ( "web3" ) web3 = new Web3 ( new Web3 . providers . HttpProvider ( "http://localhost:8545" ));
const bytecode = ' 0x1234 ....
const abi = .... web3 . eth . personal . unlockAccount ( '0x123...' , 'password' )
var thisContract = new web3 . eth . Contract ( abi , { from : '0x123...' , gasPrice : '20000000000'
}); thisContract . deploy ({ data : bytecode }). estimateGas ( function ( err , gas ) { console . log ( gas ); }); thisContract . deploy ({ data : bytecode }). send ({ from : '0x123...' , gas : 5000000 , gasPrice : '3000000000'
},
function ( error , transactionHash ) { console . log ( error ); console . log ( transactionHash ); console . log ( 'function exec' );
}). then ( function ( newContractInstance ) { console . log ( 'Contract Instance:' + newContractInstance . options . address );
});
Ich weiß jedoch nicht, wo ich in dem obigen Prozess (1) the contract balance
(da sein constructor
payable
) und (2) the constructor's parameters value
(dh (address _recipient, uint256 duration)
) (address _recipient, uint256 duration)
?
Hinweis: Ich denke, ich muss diesen Vertrag zuerst mit remix
bereitstellen, wobei ich die constructor's parameters values
des constructor's parameters values
und dann generierten bytecode
und abi
durch remix
im obigen Code web3.js verwende. Ich bin mir jedoch nicht sicher, wo ich den value: web3.toWei(1/*contract balance*/, 'ether')
verwenden value: web3.toWei(1/*contract balance*/, 'ether')
.
Schauen Sie sich das Beispiel an :
const thisContract = new web3 . eth . Contract ( abi ); thisContract . deploy ({ data : bytecode , arguments : [ "0x2345..." , 12000 ] <- Here you put your constructor arguments in order }). send ({ from : "0x1234..." , gas : 5000000 , gasPrice : '3000000000' , value : 120 <- Here you put how many wei to send to the constructor
},
function ( error , transactionHash ) ...
sas
signPayment
Funktion zusignPayment
(der vollständige Code ist hier ). Also habe ich den JavaScript-Code in einer.js
Datei gespeichert (Sie können den Inhalt dieser.js
Datei HIER sehen .) Wenn ich diese Datei jedoch über dennode filename.js
ausführe, erhalte ich dieerror message
dass ich den Screenshot HIER hochgeladen habe . Ich weiß nicht, wo ich falsch liege. Danke noch einmal.Xavier Leprêtre B9lab
Xavier Leprêtre B9lab
callback
durch diefunction(err, something) {}
ersetzen.sas
sas